1

I have a 100 images named Image-1.pdf to Image-100.pdf. Is there a way to include all of them in one slide each without having to type out each name in 100 slides and doing \includegraphics on each slide?

Romain Picot
  • 6,730
  • 4
  • 28
  • 58

3 Answers3

6

There are many ways to implement loops in LaTeX. One possibility is the pgffor package (see section 83 "Repeating Things: The Foreach Statement" of the tikz documentation):

\documentclass{beamer}
\usepackage{pgffor}
\usepackage{graphicx}

\begin{document}
\begin{frame}
    \foreach \i in {1,...,3}{
        \includegraphics<+>[width=\linewidth]{img/image-\i}
    }
\end{frame}
\end{document}
jakun
  • 5,981
6

enter image description here

Beamer comes with a command, which does exactly this: \multiinclude

\documentclass{beamer}
\usepackage{xmpmulti}
\begin{document}

    \begin{frame}
        \multiinclude[<+->][format=pdf, graphics={width=\textwidth}, start=1]{Image}
    \end{frame}

\end{document}

You can even animate the sequence using something like \transduration<0-100>{0.5}.

2

My way of doing this is a combined effort of the filecontents and csvsimple packages. Within the filecontents environment you just list the images to be used (this is helpful when you have no uniform image name pattern).

\documentclass{beamer}
\usepackage{filecontents,csvsimple}

\begin{document}

\graphicspath{{<insert/path/to/image/folder>}}

\begin{filecontents*}{imagelist.txt}
Image-1
Image-2
Image-3
\end{filecontents*}

\frame{\csvreader[no head]{imagelist.txt}{}{\centering\only<+>{\includegraphics{\csvcoli}}}}

\end{document}

Note below (and not part of the original question): if you need automatic portrait/landscape selection of the included images, you might want to look at Dedicated pages for figures featuring automatic fit-to-page scaling and automatic portrait/landscape selection

Harry
  • 4,021