Kiera.K
Kiera.K

Reputation: 367

How to join the vertical lines while adding newline to table cells

My code is as follows :

\begin{table*}[!htbp]
\centering
\begin{tabular}{ |c|c|c|c|c|c|c| } 
 \hline
 Models &  Architecture & Val & Test Acc (FF)  & Test Acc (BD) & Test Acc\\ \hline 
 VisualBert  & Single Cross-Modal Transformer & 51.0\% & 50.8\% &  51.1\% & 50.5\% \\\\ \hline
 VilBert & One Single Modal Transformer \\ & (Language) \\ & + one cross-modal transformer \\ & (with restricted attention pattern) & 51.2\% & 50.9\% & 51.2\% &  52.6\% \\\\ \hline
 LXMERT & Two Single Modal Transformer \\ & (Vision and Language) \\ & + one cross-modal transformer \\ & (with restricted attention pattern) & 53.8\% & 52.2\%  & 51.0\%& 52.9\% \\\\ \hline
 Unicoder-VL & Single Cross-Modal Transformer & 53.8\% & 52.2\%  & 51.0\%& 52.9\% \\\\ \hline
 CLIP & Base Model: ResNet50 + \\ & masked self-attention transformer \\ & or \\ & ViT + text transformer & 53.8\% & 52.2\%  & 51.0\%& 52.9\% \\\\ \hline
 SLIP & ViT/B-16 and L-16 + \\ & text transformer from CLIP & 53.8\% & 52.2\%  & 51.0\%& 52.9\% \\\\\hline
\end{tabular}
\caption{Model performance on Bongard LOGO on a reduced resolution. The test accuracy is reported on different dataset splits, including free-form shape test set (FF), basic shape test set (BA), combinatorial abstract shape test set (CM), and novel abstract shape test set (NV)}
\label{tab:baseline}
\end{table*}

But this is my output: enter image description here

How do I complete the vertical lines and print the first column text as bottom aligned? Please help! Thank you!

Upvotes: 2

Views: 1073

Answers (1)

Preface:

Don't use vertical lines in tables.

(have a look at https://wiert.files.wordpress.com/2014/04/zy8dkpa.gif for some tips on professional looking tables)


\\ won't add line breaks to your cell, it will add completely new rows to your table and you have to make sure that each row of your table has the same number of cells. Don't just prematurely finish the row with \\, instead add empty cells if necessary:

\documentclass{article}

\begin{document}

\begin{table*}[!htbp]
\centering
\begin{tabular}{ |c|c|c|c|c|c|c| } 
 \hline
 Models &  Architecture & Val & Test Acc (FF)  & Test Acc (BD) & Test Acc\\\hline 
 VisualBert  & Single Cross-Modal Transformer & 51.0\% & 50.8\% &  51.1\% & 50.5\% \\ \hline
  & One Single Modal Transformer &&&& \\ & (Language) &&&& \\ & + one cross-modal transformer &&&& \\ VilBert & (with restricted attention pattern) & 51.2\% & 50.9\% & 51.2\% &  52.6\%  \\ \hline
\end{tabular}
\caption{Model performance on Bongard LOGO on a reduced resolution. The test accuracy is reported on different dataset splits, including free-form shape test set (FF), basic shape test set (BA), combinatorial abstract shape test set (CM), and novel abstract shape test set (NV)}
\label{tab:baseline}
\end{table*}

\end{document}

enter image description here

That being said, manually adding line breaks seems unnecessarily tedious. I suggest to let latex do the line breaks for you. This is particularly easy with the tabularray package:

\documentclass{article}

\usepackage{tabularray}

\usepackage[hmargin=2cm]{geometry}

\begin{document}

\begin{table*}[!htbp]
\centering
\begin{tblr}{ |c|X[valign=b,halign=c]|c|c|c|c|c| } 
 \hline
 Models &  Architecture & Val & Test Acc (FF)  & Test Acc (BD) & Test Acc\\\hline 
 VisualBert  & Single Cross-Modal Transformer & 51.0\% & 50.8\% &  51.1\% & 50.5\% \\ \hline
 VilBert & One Single Modal Transformer (Language) + one cross-modal transformer (with restricted attention pattern) & 51.2\% & 50.9\% & 51.2\% &  52.6\%  \\ \hline
\end{tblr}
\caption{Model performance on Bongard LOGO on a reduced resolution. The test accuracy is reported on different dataset splits, including free-form shape test set (FF), basic shape test set (BA), combinatorial abstract shape test set (CM), and novel abstract shape test set (NV)}
\label{tab:baseline}
\end{table*}

\end{document}

enter image description here

Upvotes: 2

Related Questions