2

This MWE gives me the reference of the frame (1) not the slide (2). I need to have the number of the slide where is a label, how to do this?

\documentclass{beamer}
\begin{document}

\begin{frame}[label=frame]

\begin{itemize}[<+->]

\item 
\item \label{slide}
\item \ref{slide}
\end{itemize}

\end{frame}

\end{document}
Tarass
  • 16,912

1 Answers1

3

The main problem is that the \label is created on the first slide of the frame, so even if one were to create a new counter or use something like

\makeatletter
\newcommand{\mylabel}[2]% #1 = label name, #2 = text for \ref
{\protected@write\@auxout{}{\string\newlabel{#1}{{#2}{\thepage}}}}
\makeatother

it would always refer to the first slide of the frame. To illustrate this, consider the following:

\documentclass{beamer}
\begin{document}

\begin{frame}[label=frame]

\begin{itemize}[<+->]

\item \thepage
\item \label{slide}
\item \ref{slide}
\item \pageref{slide}
\item \pageref{frame<2>}
\end{itemize}

\end{frame}

\end{document}

BTW, you need to run this twice to get rid of the ??.


Based on the hint from Tarass:

\documentclass{beamer}
\usepackage{hyperref}

\makeatletter
\newcommand{\mylabel}[1]% #1 = label name
{\bgroup
\advance\c@beamerpauses by -1 %normally off by 1
\hypertarget<\thebeamerpauses>{#1}{}%
\only<\thebeamerpauses>{\protected@write\@auxout{}{\string\newlabel{#1}{{\thebeamerpauses}{\thepage}{}{#1}}}}
\egroup}
\makeatother

\begin{document}
\begin{frame}[label=frame]
\begin{itemize}[<+->]
\item
\item \mylabel{slide}
\item \ref{slide}
\end{itemize}
\end{frame}

\begin{frame}
\frametitle{page vs. beamerpauses}
Page \thepage\par
beamerpauses \thebeamerpauses
\begin{itemize}[<+->]
\item beamerpauses \thebeamerpauses
\item beamerpauses \thebeamerpauses
\end{itemize}
\end{frame}

\end{document}
John Kormylo
  • 79,712
  • 3
  • 50
  • 120