4

I'm trying to create a table with a few images in and it's mostly done apart from the images seemingly overlap with the cell lines deleting them. A shorter MWE is below (the full table will contain around 20 images) along with a picture of what's happening, if anyone could help me with justifying the images within the cells as well that would be great.

\documentclass{report}
\usepackage{longtable}
\usepackage{graphicx}

\begin{document}
\\begin{center}
\begin{longtable}{|l|l|l|}
 \caption{Molecular structures of the molecules chosen in the blind test}\label{big_tab} \\
\hline Molecular Structure & Category & Blind test \\ \hline 
\endfirsthead

\multicolumn{3}{c}%
{{\bfseries \tablename\ \thetable{} -- continued from previous page}} \\
\hline Molecular Structure & Category & Blind test \\ \hline 
\endhead

\hline \multicolumn{3}{|r|}{{Continued on next page}} \\ \hline
\endfoot

\hline \hline
 \endlastfoot

\includegraphics[width=1in]{I.png} & i & \multicolumn{ 1}{c|}{1st} \\ \cline{ 1- 2}
\includegraphics[width=1in]{II.png} & ii & \multicolumn{ 1}{l|}{} \\ \cline{    1- 2}
\includegraphics[width=2in]{III.png} & iii & \multicolumn{ 1}{l|}{} \\   \hline
\includegraphics[width=1in]{IV.png} & i & \multicolumn{ 1}{c|}{2nd} \\  \cline{ 1- 2}
\includegraphics[width=1in]{V.png} & ii & \multicolumn{ 1}{l|}{} \\ \cline{ 1- 2}
\includegraphics[width=2in]{VI.png} & iii & \multicolumn{ 1}{l|}{} \\ \hline
\end{longtable}
\end{center}

\end{document}

enter image description here

5
  • That's not expected. This is with pdflatex? Apr 11, 2014 at 13:11
  • you could add array package and add \setlength\extrarowheight{2pt}` or whatever length works, but you should not have to do that. Apr 11, 2014 at 13:12
  • The compilation option on my visualiser is set to TexLive with PdfTex, I'll have a look at the array package
    – Jsg91
    Apr 11, 2014 at 13:22
  • We don't have access to those images, we are guessing here, isn't the problem caused by the PDF viewer? Could you please try to zoom in?
    – Malipivo
    Apr 11, 2014 at 13:35
  • I know, I did need to show the problem though, I've viewed it in another viewer and printed the page out but the issue remains, edit: adding enough extra row height does sort of solve it though
    – Jsg91
    Apr 11, 2014 at 13:38

1 Answer 1

3

The problem is that \includegraphics inside a tabular leaves no space above the image, so it abuts the dividing line. Here, I use the \addvbuffer macro of the verbatimbox package to add a 3pt buffer above (and 0pt below) the image, and call that new form \Includegraphics, with a cap I.

\documentclass{report}
\usepackage{longtable}
\usepackage[demo]{graphicx}
\usepackage{verbatimbox}
\newcommand\Includegraphics[2][]{\addvbuffer[3pt 0pt]{\includegraphics[#1]{#2}}}

\begin{document}
\begin{center}
\begin{longtable}{|l|l|l|}
 \caption{Molecular structures of the molecules chosen in the blind test}\label{big_tab} \\
\hline Molecular Structure & Category & Blind test \\ \hline 
\endfirsthead

\multicolumn{3}{c}%
{{\bfseries \tablename\ \thetable{} -- continued from previous page}} \\
\hline Molecular Structure & Category & Blind test \\ \hline 
\endhead

\hline \multicolumn{3}{|r|}{{Continued on next page}} \\ \hline
\endfoot

\hline \hline
 \endlastfoot

\Includegraphics[width=1in]{I.png} & i & \multicolumn{ 1}{c|}{1st} \\ \cline{ 1- 2}
\Includegraphics[width=1in]{II.png} & ii & \multicolumn{ 1}{l|}{} \\ \cline{    1- 2}
\Includegraphics[width=2in]{III.png} & iii & \multicolumn{ 1}{l|}{} \\   \hline
\Includegraphics[width=1in]{IV.png} & i & \multicolumn{ 1}{c|}{2nd} \\  \cline{ 1- 2}
\Includegraphics[width=1in]{V.png} & ii & \multicolumn{ 1}{l|}{} \\ \cline{ 1- 2}
\Includegraphics[width=2in]{VI.png} & iii & \multicolumn{ 1}{l|}{} \\ \hline
\end{longtable}
\end{center}

\end{document}

enter image description here

3
  • yes (my suggestion of using \extrarowheight is similar) but the image is apparently showing it overprinting rather than abutting the line which indicates (unless it comes and goes at different zoom levels) that pdftex has misread the size of the image which would indicate a bug somewhere. (of course for the user, adding padding is the solution whether or not it's a bug, but I'd like to know:-) Apr 11, 2014 at 13:47
  • @DavidCarlisle I assumed it to be a rendering problem, too. And as Dr. Tabular, you indeed would want a definitive understanding of the point you raise. Apr 11, 2014 at 13:51
  • This is indeed a solution thank you! The clipping doesn't go away with zoom level, using the extrarowheight fixes some cells and clips others depending on the value chosen.
    – Jsg91
    Apr 11, 2014 at 13:59

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .