[Tex/LaTex] Showing step by step using images in single frame

beamergraphics

I would like to show an series of images in a step-by-step manner (PowerPoint like) in Beamer. Currently, I just create a series of frames with one image for each:

\begin{frame}
    \frametitle{Main Title}
    \framesubtitle{Subtitle}
    \centering
    \includegraphics[width=.8\textwidth]{figures/image1.pdf} \\
\end{frame}
\begin{frame}
    \frametitle{Title}
    \framesubtitle{Subtitle}
    \centering
    \includegraphics[width=.8\textwidth]{figures/image2.pdf} \\
\end{frame} 

I read that there is a way to layer text e.g. alert highlights by using \altert<2>{This is important!}. I tried to use this code to follow this example, without success:

\begin{frame}
    \frametitle{Title}
    \framesubtitle{Subtitle}
    \centering
    \includegraphics<1>[width=.8\textwidth]{figures/image1} \\
    \includegraphics<2>[width=.8\textwidth]{figures/image2} \\
\end{frame} 

Is there a better way? This can mean a lot less code with 5+ images in a sequence. This also has the advantage that the handout would only have the last one in and not the entire progress — saving me a lot of slides that students would not need to print. Any ideas?

Best Answer

It's possible to loop over the images of course, for example, with \foreach from pgffor.

\documentclass[draft]{beamer}

\usepackage{pgffor}

\begin{document}

\begin{frame}
    \frametitle{Title}
    \framesubtitle{Subtitle}
    \centering
    \foreach \x in {1,...,5} {%
    \includegraphics<\x>[scale=0.5]{a_\x.jpg}%
    }
\end{frame} 
\end{document}

enter image description here

Related Question