0

I am using the longtable LaTeX package to create a multi-page table with three columns, one of which contains only images. However, the vertical line between the middle and right column does not complete up to the top \hline as seen in the screenshot. Screenshot of error

This is the code I'm using to create the table. I removed most of the lines to make it viable easier because it's basically the same line repeated over.

\begin{longtable}{m{0.5\textwidth}|m{0.25\textwidth}|m{0.15\textwidth}}
Thumbnail & Description & Number of Images \\
\hline \\
\endhead

\includegraphics[width=0.45\textwidth]{img/data/some_img1.png} & Description 1 & 2 \\
\includegraphics[width=0.45\textwidth]{img/data/some_img2.png} & Description 2 &  10 \\

\caption{Gathered Data}
\label{tbl:some_data_table}\\
\end{longtable}

Thanks!

  • 1
    Welcome to TeX.SE! Remove \\ after first \hline. – Zarko Jul 28 at 1:13
1

As Zarko already mentioned in the comments, you can get rid of the undesired gap in the vertical line by removing the \\ after \hline:

enter image description here

\documentclass{article}

\usepackage{longtable}
\usepackage{graphicx}
\usepackage{array}

\begin{document}


\begin{longtable}{m{0.5\textwidth}|m{0.25\textwidth}|m{0.15\textwidth}}
Thumbnail & Description & Number of Images \\
\hline 
\endhead

\includegraphics[width=0.45\textwidth]{example-image} & Description 1 & 2 \\
\includegraphics[width=0.45\textwidth]{example-image} & Description 2 &  10 \\

\caption{Gathered Data}
\label{tbl:some_data_table}\\
\end{longtable}


\end{document}

As you can see, removing the \\ also removed the small vertical whie space between the \hline and the first image. If you want to keep such a space around the images, I'd sugggest the usage of the cellspace package. In teh following MWE, I have also used the xltabular package in order to make the table as wide as the textwidth without the need to calculate the required column widths manually. I have also added the adjustbox package in order to use the valing option. Lastly, I have also moved the \caption to the top of the table as it might be a good idea to inform the reader what the table is about before starting the actual table. Especially if your table is longer than one page.

enter image description here

\documentclass{article}

\usepackage{xltabular}
\usepackage{graphicx}
\usepackage{array}


\usepackage[export]{adjustbox}
\usepackage{cellspace}
\setlength\cellspacetoplimit{\tabcolsep}
\setlength\cellspacebottomlimit{\tabcolsep}
\usepackage{makecell}

\begin{document}


\begin{xltabular}{\textwidth}{Sc|X|l}
\caption{Gathered Data}\label{tbl:some_data_table}\\
\makecell[l]{Thumbnail} & Description & \makecell[l]{Number of\\ Images} \\
\hline
\endhead

\includegraphics[width=0.45\textwidth,valign=c]{example-image} & Description 1 & 2 \\
\includegraphics[width=0.45\textwidth,valign=c]{example-image} & Description 2 &  10 \\
\end{xltabular}

\end{document}

Personally, I'd also remove the vertical lines entirely and use horizontal lines from the booktabs package. I would also top align the contents of the cells:

enter image description here

\documentclass{article}

\usepackage{xltabular}
\usepackage{graphicx}
\usepackage{array}


\usepackage[export]{adjustbox}
\usepackage{cellspace}
\setlength\cellspacetoplimit{\tabcolsep}
\setlength\cellspacebottomlimit{\tabcolsep}
\usepackage{makecell}

\usepackage{booktabs}

\begin{document}


\begin{xltabular}{\textwidth}{@{}ScXl}
\caption{Gathered Data}\label{tbl:some_data_table}\\
\toprule
\multicolumn{1}{l}{Thumbnail} & Description & \makecell[l]{Number of\\ Images} \\
\midrule
\endhead
\bottomrule
\endfoot

\includegraphics[width=0.45\textwidth,valign=t]{example-image} & Description 1 & 2 \\
\includegraphics[width=0.45\textwidth,valign=t]{example-image} & Description 2 &  10 \\
\end{xltabular}

\end{document}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.