4

Is there any elegant way to layout multiple images like this automatically:

\begin{figure}
    \centering
    \includegraphics[width=0.32\textwidth]{eval1.pdf}%
    \includegraphics[width=0.32\textwidth]{eval2.pdf}%
    \includegraphics[width=0.32\textwidth]{eval3.pdf}
    \\
    \includegraphics[width=0.32\textwidth]{eval4.pdf}%
    \includegraphics[width=0.32\textwidth]{eval5.pdf}%
    \includegraphics[width=0.32\textwidth]{eval6.pdf}
    \caption{Results for four scenarios}
    \label{results}
\end{figure}

This methods becomes somewhat tedious when using different layouts like 5x2 or 6x2. I would like to say "use x% of the maximal available width for theses n images and put a white space of d between them".

Edit: This question previously also included a problem with the missing % which screwed up a 2x2 layout when using 0.5\textwidth instead of 0.49\textwidth. Thanks to Torbjørn for pointing this out!

ShreevatsaR
  • 45,428
  • 10
  • 117
  • 149
Danvil
  • 185
  • 2
    The line break between the \includegraphics creates a space, add a % at the end of the line. – Torbjørn T. Aug 18 '13 at 16:17
  • @TorbjørnT. Now it's my turn... Can you turn it to an answer? – karlkoeller Aug 18 '13 at 17:47
  • @karlkoeller Not sure, then it could perhaps be closed as a duplicate of http://tex.stackexchange.com/questions/19922/where-are-the-necessary-places-to-be-appended-with-to-remove-unwanted-spaces Also, it doesn't really answer the more general question. – Torbjørn T. Aug 18 '13 at 17:53
  • @TorbjørnT. Probably this one http://tex.stackexchange.com/q/23835/27635 – karlkoeller Aug 18 '13 at 18:33
  • So theses are basically two questions and I would be interested in the more general. So I edit the question accordingly. – Danvil Aug 18 '13 at 19:37
  • http://tex.stackexchange.com/questions/125675/automatic-scaling-of-tikz-images-in-floatrow/125722#125722 may be relevant, too. – Steven B. Segletes Aug 18 '13 at 20:04

1 Answers1

4
\begin{figure}
    \centering

    \setkeys{Gin}{width=0.32\textwidth}
    \includegraphics{eval1.pdf}\hfill
    \includegraphics{eval2.pdf}\hfill
    \includegraphics{eval3.pdf}\hfill
    \includegraphics{eval4.pdf}\hfill
    \includegraphics{eval5.pdf}\hfill
    \includegraphics{eval6.pdf}

    \caption{Results for four scenarios}
    \label{results}
\end{figure}

Then you just need to set the width of each figure once, there is no need for manually adding \\ TeX will use its normal paragraph breaking algorithm to distribute the images to lines as needed.

David Carlisle
  • 757,742