[Tex/LaTex] Inserting figures using loops

graphicsloops

I have a set of pictures in my working directory and I want to make a PDF report using these images. I want to include all of them, but the number of the pictures changes in each case. I would like to make a "for" loop to insert each picture one after the other sequentially. Can anyone help me?
At the moment the code I have is the following:

\begin{figure}[h!]
\begin{centering}
\includegraphics[width=10cm,height=10cm]{Figure1.png}
\caption[Sèries temporals de vent i direccions]{Sèries temporals velocitat de vent i     direccions. filtratge de pics i glaçades de velocitat.}
\label{Serie}
\end{centering}

\end{figure}

I would like to do it for every .png image in the directory.
Thanks for your questions: I am using Windows 7 and the file names follow the pattern Figura1.png, Figura2.png and so forth. So which of these possibilities would fit best?

Best Answer

Suppose your pictures are all following certain naming convention (here I used pic1.png up to pic4.png), the lipsumpackage is just for the dummy text:

\documentclass[parskip]{scrartcl}
\usepackage[margin=10mm,a6paper]{geometry}
\usepackage{tikz}
\usepackage{lipsum}

\begin{document}

\foreach \x in {1,2,3,4}
{ \lipsum[\x]
    \includegraphics[scale=1]{pic\x.png}
    \clearpage
}

\end{document}

Alternatively, you can specify tuples of variable to iterate over. The following does the same:

\foreach \x/\picname in {4/pic1.png,8/pic2.png,15/pic3.png,16/pic4.png}
{ \lipsum[\x]
    \begin{figure}[htb]
        \includegraphics[scale=1]{\picname}
        \caption{The very nice picture \x}
    \end{figure}
    \clearpage
}

And the output being:

enter image description here

Related Question