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?

  • Is your problem solved? If yes, then accept an answer (the one that you like most). – Dr. Manuel Kuehner Apr 27 '17 at 20:30
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}
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

  • You actually don't need graphicx with beamer. – user36296 Apr 26 '17 at 15:48
  • @samcarter Thank you, I wasn't aware of that. I've edited my answer accordingly. – Harry Apr 26 '17 at 15:54
  • You can simplify it even more if you use \includegraphics<+>{\csvcoli} instead of the \only command – user36296 Apr 27 '17 at 16:23
  • @samcarter And thanks again for helping me improve. – Harry Apr 28 '17 at 11:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.