1

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:

Eight images with same scale in a single figure, demonstrating inconsistent spacing of the final image

4
  • Welcome, check the images in an external viewer. Some of them have more whitespace than others.
    – Johannes_B
    Commented Dec 3, 2016 at 7:04
  • ...or print them all with a surrounding \fbox and see where the bounding box lies.
    – Werner
    Commented Dec 3, 2016 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
    Commented Dec 3, 2016 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
    Commented Dec 3, 2016 at 16:41

2 Answers 2

2

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.

4
  • Looks perfect. Thanks for explaining the logic behind it too.TIL: When in doubt, tell tex EXACTLY what to do.
    – BobRz
    Commented Dec 3, 2016 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
    Commented Dec 3, 2016 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
    Commented Dec 4, 2016 at 19:48
  • @user1202809 -- very poetic, and accurate too! :-)
    – Mico
    Commented Dec 4, 2016 at 19:52
1

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.

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

You must log in to answer this question.

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