6

For space reasons I want to break up the contents of an itemize list into separate slides, which I have been doing without much problem using \only. However, the following minimal document complains that the label eq:formula is not defined:

\documentclass{beamer}
\begin{document}
\begin{frame}{Title}
 \begin{itemize}
 \only<1>{
  \item Item 1.
 }             % Comment 
 \only<2>{     % these lines
  \item Item 2, with equation
  \begin{equation}
   \label{eq:formula}
   xyz
  \end{equation}

  \item Item 3, with reference \eqref{eq:formula}.
 }
 \end{itemize}
\end{frame}
\end{document}

As you can see, it is clearly defined. The problem goes away if you comment out the marked lines (thus, printing everything on one slide). I see using \tracingmacros that there is a serious redefinition of \label in beamer, and as such it appears that this is a bug with detecting what slide the label is printed on.

Is that right, and what is the solution?

8

beamer's \label is also overlay-aware. Following \show\label (outside the frame environment), you'll notice

> \label=macro:
->\@ifnextchar <{\beamer@label }{\beamer@label <1>}

which implies \label{<stuff>} without an overlay specification defaults to \label<1>{\stuff>} making it only label on slide 1 by default. This, of course, motivates why having only a single slide makes the references work as expected. Consequently, use \label<2>{eq:formula} for the label to be active on slide 2.

Here's the complete MWE:

enter image description here

\documentclass{beamer}% http://ctan.org/pkg/beamer
\begin{document}
\begin{frame}{Title}
 \begin{itemize}
 \only<1>{%
  \item Item 1.
 }
 \only<2>{%
  \item Item 2, with equation
  \begin{equation}
   \label<2>{eq:formula}
   xyz
  \end{equation}

  \item Item 3, with reference \eqref{eq:formula}.
 }
 \end{itemize}
\end{frame}
\end{document}

True, it would be nice if \label was self-sufficiently slide-aware...

  • I see, not a bug but a feature :) – Ryan Reich Feb 15 '12 at 2:13

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.