3

I'm placing images into a table, but they aren't lining up vertically, even though they are the same height. A complete example is:

\documentclass{llncs}
\usepackage{amsmath}
\usepackage{array}
\usepackage{graphicx}
\setlength{\tabcolsep}{6pt}
\newcolumntype{C}[1]{>{\centering\let\newline\\\arraybackslash\hspace{0pt}}m{#1}}

\begin{document}

\begin{figure}[htbp]
\begin{center}
\begin{tabular}{ C{2.5cm} C{2.5cm}}
\includegraphics[height = 1.75in]{size.pdf} & \includegraphics[height = 1.75in]{back1.pdf} \\
(a) & (b) \\
\end{tabular}
\caption{This isn't laying out properly.}
\label{boards}
\end{center}
\end{figure}

\end{document}

Here are the images I want to line up:

Notice how they line up nicely in the html -- they are the same height. But, this is the output I get.

It is something about this macro which is causing the problem, in conjunction with images which are the same height, but different width.

\newcolumntype{C}[1]{>{\centering\let\newline\\\arraybackslash\hspace{0pt}}m{#1}}

If I use c, everything works. If I layout the same image twice I don't have any problems:

\begin{tabular}{ c c}
\includegraphics[height = 1.75in]{back1.pdf} & \includegraphics[height = 1.75in]{back1.pdf} \\
(a) & (b) \\
\end{tabular}

Can anyone explain what is causing this issue? (In this context I can fix the issue, but I'm interested in understanding the underlying cause of the issue.)

1

It ends up that I found the answer unexpectedly. The 2.5cm allotted for each column and 1.75in height isn't quite enough to fit the full image. So, the larger image was being scaled slightly by latex, causing the mis-alignment. Allotting 2.6cm for each column fixes it.

(I should have looked at the error console, as it warned me:

Overfull \hbox (1.31029pt too wide) in paragraph at lines 13--13

But TeXShop hides it when showing the .pdf, so I forgot to check.)

0

It's difficult to diagnose the problem, but I suspect that the problem is the leftmost image is wider than 2.5cm, so TeX is forced to create a two line paragraph.

I'm not sure why you specify the height instead of the width: if you set the height, you need to guess a width.

But that's not really important provided you use a normal c specifier: if you want to distance the two images, just act on the intercolumn space, changing the value where I type \hspace{12pt}.

I provided both alternatives (one is commented out), take your pick.

\documentclass{llncs}
\usepackage{amsmath}
\usepackage{graphicx}

\begin{document}

\begin{figure}[htbp]
\centering

\begin{tabular}{ @{} c @{\hspace{12pt}} c @{} }
\includegraphics[width=2.5cm]]{size.pdf} & \includegraphics[width=2.5cm]{back1.pdf} \\
%\includegraphics[height = 1.75in]{back1.pdf} & \includegraphics[height = 1.75in]{back1.pdf} \\
(a) & (b)   
\end{tabular}
\caption{This should go properly}
\label{boards}

\end{figure}

\end{document}
  • Both of the images have the same height, but different widths. So, if I specify the width of the image, I will get different heights. So, your commented out solution works, but not the one that sets widths. In practice I'm actually using more columns, for which I needed the alternate C specification. – Nathan S. May 12 '15 at 16:29

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.