# With multiple images in one figure, why is the last image spaced differently?

I have a figure with eight images of the same size. They fit two to a row and the first three rows look great, but the fourth row gets weird; where the first three have their images spaced apart left-to-right, the final row has them left-aligned next to each other without a gap.

My original code is below with eight images scaled to 25%, however I've tried it with:

• Eight images scaled to 20%
• Six images scaled to 25%
• Six images scaled to 20%

And seen the same behavior each time -- the last image is always aligned differently.

Code:

\begin{figure}[h]
\caption{2.68 logic tests}
\includegraphics[scale=.25]{3x8_decoder_0}
\includegraphics[scale=.25]{3x8_decoder_1}
\includegraphics[scale=.25]{3x8_decoder_2}
\includegraphics[scale=.25]{3x8_decoder_3}
\includegraphics[scale=.25]{3x8_decoder_4}
\includegraphics[scale=.25]{3x8_decoder_5}
\includegraphics[scale=.25]{3x8_decoder_6}
\includegraphics[scale=.25]{3x8_decoder_7}
\label{fig:3x8proof}
\end{figure}


Example of the original problem:

• Welcome, check the images in an external viewer. Some of them have more whitespace than others. – Johannes_B Dec 3 '16 at 7:04
• ...or print them all with a surrounding \fbox and see where the bounding box lies. – Werner Dec 3 '16 at 7:25
• The pictures are lined up with a space in between, and output as a normal paragraph. With that size of the picture you only fit two on each row so you end up with four rows. The last picture is not right aligned since it is the last row. – StefanH Dec 3 '16 at 8:18
• The images are all the same size (cropped them all with ImageMagick's convert) but good thing to check for anyone having a similar problem. – BobRz Dec 3 '16 at 16:41

The line breaks are currently falling serendipitously but randomly after every second picture. To make the intended look more explicit, you could write

\begin{figure}[h]
\caption{2.68 logic tests} \label{fig:3x8proof}

\includegraphics[scale=.25]{3x8_decoder_0}\hfill
\includegraphics[scale=.25]{3x8_decoder_1}

\includegraphics[scale=.25]{3x8_decoder_2}\hfill
\includegraphics[scale=.25]{3x8_decoder_3}

\includegraphics[scale=.25]{3x8_decoder_4}\hfill
\includegraphics[scale=.25]{3x8_decoder_5}

\includegraphics[scale=.25]{3x8_decoder_6}\hfill
\includegraphics[scale=.25]{3x8_decoder_7}
\end{figure}


The blank lines will force line breaks, and the \hfill instructions will space the graphs maximally apart.

• Looks perfect. Thanks for explaining the logic behind it too.TIL: When in doubt, tell tex EXACTLY what to do. – BobRz Dec 3 '16 at 16:38
• @user1202809 - Thanks. The corollary to your "when in doubt" saying is: "Make something foolproof, and only a fool will want to use it." TeX and LaTeX make no claim to be foolproof. In my view, that's exactly why non-fools appreciate TeX and LaTeX so much... – Mico Dec 3 '16 at 16:44
• It's a complex system that, with mastery, can be bent to the non-fool's will to create precise and beautiful output; the typesetting equivalent of a set of fine chisels. – BobRz Dec 4 '16 at 19:48
• @user1202809 -- very poetic, and accurate too! :-) – Mico Dec 4 '16 at 19:52

Can't tell you why, but I can help you out with a workaround.

\begin{figure}[h]
\caption{2.68 logic tests} \label{fig:3x8proof}
\begin{minipage}{.5\textwidth}
\includegraphics[scale=.25]{3x8_decoder_0}\\
\includegraphics[scale=.25]{3x8_decoder_2}\\
\includegraphics[scale=.25]{3x8_decoder_4}\\
\includegraphics[scale=.25]{3x8_decoder_6}
\end{minipage}%
\begin{minipage}{.5\textwidth}
\begin{flushright}
\includegraphics[scale=.25]{3x8_decoder_1}\\
\includegraphics[scale=.25]{3x8_decoder_3}\\
\includegraphics[scale=.25]{3x8_decoder_5}\\
\includegraphics[scale=.25]{3x8_decoder_7}
\end{flushright}
\end{minipage}
\end{figure}


Don't forget that \textwidth inside of the minipage is based on the size of the minipage So in this case .5 inside the minipage would correspond to .25 of the entire sites textwidth.

Just a little fix to workaround the \textwidth + eps figure, which would be wider than actual \textwidth.

• How so? Never did it and was always working fine. – Patrick Abraham Dec 3 '16 at 9:07
• I see, really good to know. – Patrick Abraham Dec 3 '16 at 16:37