5

I am preparing a presentation with several very similar slides so I would like to use a \foreach loop with \only to generate them. The frames also contains minipages and these minipages seem to cause the slides to be shifted horizontally as I scroll through the presentation.

MWE:

\documentclass{beamer}
\usepackage{tikz}

\begin{document}
\begin{frame}
\foreach\x in {1,...,9}{
\begin{minipage}{.5\textwidth}
\only<\x>{
\begin{tikzpicture}
\draw (0,0) -- (0,10);
\draw (0,5) -- (5,\x);
\end{tikzpicture}
}
\end{minipage}
}
\end{frame}
\end{document}

Why do I get this behaviour? Is the minipage taking up space on all slides (even though it doesn't show on all)?

1 Answer 1

6

Sometimes spurious " " (white space) are important in beamer and you need to eliminate them with %. I don't know if all of them are necessary but next code works as expected:

\documentclass{beamer}
\usepackage{tikz}

\begin{document}
\begin{frame}

\foreach\x in {1,...,9}{%
\begin{minipage}{.5\textwidth}%
\only<\x>{%
\begin{tikzpicture}
\draw (0,0) -- (0,10);
\draw (0,5) -- (5,\x);
\end{tikzpicture}
}%
\end{minipage}%
}%
\end{frame}
\end{document}
1
  • 1
    Wow, I would never have figured that out. Seems like it is crucial to comment out the end of the \foreach line and the \end{minipage} line. Thanks!
    – user49901
    May 25, 2015 at 7:42

You must log in to answer this question.