2

According to this question, labels are defined by default on a beamer slide to always be defined at the first slide <1>. Indeed \show\label shows

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

A solution is to use \label<2> for example to define labels on the second slide. I would rather not change all my labels. Instead, is there a way to redefine label so that it does not default to slide <1>, using the current slides like other commands?

  • \documentclass{beamer} \begin{document} \show\label \end{document}, shows the macro definition. – Tohiko May 21 at 11:56
1

You can redefine \label in order to change <1> to <+-> (current and following). However, this only works for regular labels and not for display labels (such as in an equation), because beamer redefines these at the start of a math environment. For such cases you can use a custom macro like \mathlabel. This is not so convenient as just using \label, but it is easier than having to figure out which number you should put.

MWE, adapted from the referenced question:

\documentclass{beamer}
\begin{document}
\makeatletter
\def\label{\@ifnextchar <{\beamer@label }{\beamer@label <+->}}
\def\mathlabel{\@ifnextchar <{\beamer@label@in@display }{\beamer@label@in@display <+->}}
\makeatother
\begin{frame}{Title}
 \begin{itemize}
 \only<1>{
  \item Item 1.
 }             
 \only<2>{     
  \item Item 2, with equation
  \begin{equation}
   \mathlabel{eq:formula}
   xyz
  \end{equation}
  \begin{figure}
  \caption{abc}
  \label{fig:empty}
  \end{figure}

  \item Item 3, with references \eqref{eq:formula} and Figure \ref{fig:empty}.
 }
 \end{itemize}
\end{frame}
\end{document}

Result:

enter image description here

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.