3

I am trying to put 6 figures in 3rows & 2 columns:

\foreach \x in {1,2,3,4,5,6,7,8,9,10,11,12}
{
\begin{figure}[h]
\caption{This is the caption.}
\vspace{0.0cm} \centering
\includegraphics[height = 5.4cm]{figures/fig\x.eps}
\end{figure}
}

I want only one caption in first figure page and same figure number for next 6 figures in next page.

1
  • 1
    Welcome to TeX.SX! Please help us to help you and add a minimal working example (MWE) that illustrates your problem. It will be much easier for us to reproduce your situation and find out what the issue is when we see compilable code, starting with \documentclass{...} and ending with \end{document}.
    – user31729
    Commented Mar 26, 2014 at 6:39

1 Answer 1

6

I have used the pgffor (or tikz) package, a pair of cycles (inner and outer) and several conditions to polish the result. In a real project I would use the subfigure package and two independent pages to get cross-references clickable to both parts.

I enclose an example and a preview of pages. Those 12 pictures (fig*) must be stored in the figures/ folder to successfully compile the code.

%! *latex morepics.tex
\documentclass[a4paper]{article}
\usepackage{pgffor}% or tikz
\usepackage{mwe}
%\usepackage{subfigure}

\begin{document}
\foreach \x in {1,2} {%
\ifnum\x=2\addtocounter{figure}{-1}\fi
\newpage
\begin{figure}%[!ht]
\centering
\caption{This is the caption.}%
\foreach \y in {1,...,6}{%
  \pgfmathparse{int((\x-1)*6+\y)}
  % We need figures/fig1 to figures/fig12 to be able to compile this particular example.
  \includegraphics[height=6.5cm]{figures/fig\pgfmathresult} 
  \ifnum\y=2\par\fi
  \ifnum\y=4\par\fi
  }% End of the inner \foreach...
\end{figure}%
}% End of the outer \foreach...
\end{document}

mwe

Edit: changes in packages: +mwe, -subfigure, -tikz, +pgffor. Instead of using figures 1-6 and using them twice, it is now loading figures 1 to 12.

8
  • 4
    Wouldn't it be easier to use subfigure from the subcaption package? Putting each subfigure to .48\textwidth or sth would be easier, i think.
    – Ronny
    Commented Mar 26, 2014 at 8:25
  • 4
    Consider to load pgffor rather than the heavy tikz; moreover, I think you're missing a call to mwe. Commented Mar 26, 2014 at 8:25
  • Thank you for an advice! To the mwe package, it might be a problem, yes, I am using only one picture which is stored and findable in the TeX structure (TeX Live), but it could be a problem with other TeX distributions (untested).
    – Malipivo
    Commented Mar 26, 2014 at 8:30
  • 1
    @Malipivo: I was mentioning mwe because your example, as it is, it is not compilable. Adding mwe to the list of loaded packages makes your mwe compilable. Please, note that for the purpose of answering, it is completely fine to use that package even if others can not compile. You can highlight that the package is used for demonstration purposes only: others have to replace with actual pictures. What I usually do is: \usepackage{mwe} % for dummy images. Commented Mar 26, 2014 at 8:43
  • @Claudio Fiandrino Thank you, I have modified the code. It was running at my computer, but thank you for letting me know! I will pay attention to this particular problem in my next posts.
    – Malipivo
    Commented Mar 26, 2014 at 8:50

You must log in to answer this question.