Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I have a large number of figures (~300) in a folder called 'allimages'. The figures are numbered fig1.eps, fig2.eps,.....fig300.eps. I want to put all of them in latex such that 6 images appear on one page. What I know to do is something like this

\begin{figure}[h]
\caption{Write the caption here.}
\vspace{0.0cm} \centering
\includegraphics[height=5.4cm]{allimages/fig1.eps}
\includegraphics[height=5.4cm]{allimages/fig2.eps}
\includegraphics[height=5.4cm]{allimages/fig3.eps}
\includegraphics[height=5.4cm]{allimages/fig4.eps}
\includegraphics[height=5.4cm]{allimages/fig5.eps}
\includegraphics[height=5.4cm]{allimages/fig6.eps}
\end{figure}

But doing like this will be time consuming. Is it possible to have some looping statement that makes it easier and help me skip long listing of figures. Thanks!

share|improve this question

migrated from stackoverflow.com Feb 18 '13 at 15:23

This question came from our site for professional and enthusiast programmers.

    
I would leave this task to my editor... Thus, what editor do you use? –  Jan Feb 17 '13 at 12:09
    
I use texshop on mac platform. I use Xcode. –  user26101 Feb 17 '13 at 12:20
    
Related: tex.stackexchange.com/questions/53458/… –  Torbjørn T. Feb 18 '13 at 15:30
2  
If you have coding skills, just write a little program in your favorite language to generate the LaTeX source code. –  Ben Crowell Feb 18 '13 at 16:14

1 Answer 1

This looks easiest to do using \foreach from the pgf bundle. To get everything on separate pages, you probably need a couple of loops:

\documentclass{article}
\usepackage[demo]{graphicx}
\usepackage{pgffor}
\usepackage{caption}
\begin{document}
\foreach\x in {0,1,...,49}{%
  \begin{center}
    \foreach\y in {1,2,...,6}{%
      \includegraphics[height=5.4cm]{allimages/fig\numexpr 6 * \x + \y\relax}
    }%
    \captionof{figure}{Images \number\numexpr 6 * \x + 1\relax\space to
      \number\numexpr 6 * \x + 6\relax.}
  \end{center}
}
\end{document}

Doing all of this with floats will run out of space quite quickly (no intervening text), so I've used the \captionof command from the caption package to generate the appropriate text.

share|improve this answer
    
PDF file only has 1 page. Only a few images that are displayed. Other images are not displayed because it exceeds the page limit. –  Edy Jo Jun 7 at 13:21
1  
@EdyJo True: I've modified to use two loops and thus ensure that each page is 'just right'. –  Joseph Wright Jun 7 at 13:36

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.