I'm trying to show a sequence of almost identical images in a beamer frame, to be able to step back and forth and compare the differences. The images are numbered as image1.pdf, image2.pdf etc., and it seemed practical to present them using a \foreach-loop.
To my surprise this seems to cause some, not all, of the images to be vertically shifted! I've boiled it down to the following MWE.
\documentclass[11pt]{beamer}
\usepackage{tikz}
\begin{document}
\begin{frame}
\begin{center}
\includegraphics[width=1\textwidth]<1>{./figs/image1}
\includegraphics[width=1\textwidth]<2>{./figs/image2}
\includegraphics[width=1\textwidth]<3>{./figs/image3}
\end{center}
\end{frame}
\begin{frame}
\begin{center}
\foreach \number in {1,2,3}{
\includegraphics[width=1\textwidth]<\number>{./figs/image\number}
}
\end{center}
\end{frame}
\begin{frame}
\begin{center}
\foreach \number in {1,2,3}{
\only<\number>{\includegraphics[width=1\textwidth]{./figs/image\number}}
}
\end{center}
\end{frame}
\end{document}
The first frame behaves as I intended, and all images are placed in the same spot.
In the second frame, all but the last two images are higher than the rest. This happens for any number of images: most are aligned but I get a shift near the end.
In the third frame, all but the very last image are shifted upwards.
As I want to compare differences between the similar images the shift is very annoying, and for now I have to go with the first construction. I have some long series though, and it would be nice to be able to avoid writing all the file names out explicitly.
Is there any way to display a series of images using a loop, which does not cause some of the images to be shifted?
%and ends of lines and perhaps\mbox{}before the\onlybut don't use\numberas your loop variable, that is the TeX primitive for accessing the decimal value of a counter and locally redefining will break large amounts of code – David Carlisle Nov 19 '21 at 13:33