Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

For my lecture slides in beamer I would like to establish a section-framenumber numbering scheme. For this purpose I reset frame counter in \AtBeginSection and redefine the \insertframenumber command to reflect the new numbering scheme:

\renewcommand{\insertframenumber}{\thesection-\theframenumber}
\AtBeginSection{\setcounter{framenumber}{0}}

This works pretty well. However, I have not succeeded in getting cross-references right in this respect, that is to refer to some labeled \frame[label=interesting] as section-framenumber. Apparently, there is no way to, given the label, extract the section number:

\documentclass{beamer}

\renewcommand{\insertframenumber}{\thesection-\theframenumber}
\setbeamertemplate{headline}[text line]{This is frame: \insertframenumber}
\AtBeginSection{\setcounter{framenumber}{0}}

\begin{document}

\section{One}
\begin{frame}{First Frame in Section One}
  Slide content\par
  \pause
  More content
\end{frame}
\begin{frame}[label=interesting]{Second Frame in Section One -- The one to crossref to}
  Slide content
\end{frame}

\section{Two}
\begin{frame}{First Frame in Section Two}

  Now I want to crossref to interesting slide by section-framenumber (that is, somehow generate \textbf{1-2}) 
  \begin{itemize}
    \item \textbackslash{}ref yields: \ref{interesting}, apparently that is the frame number
    \item \textbackslash{}page yields: \pageref{interesting}, apparently that is the PDF page number
    \item \textbackslash{}autoref yields: \autoref{interesting}, apparently that is the frame number again
    \item nothing there that yields \textbackslash{}thesection of our target label?
  \end{itemize}
\end{frame}

\end{document}

I took a look at the generated .aux-file. I am not really good in deciphering .aux-files; however, as I read it, beamer does not even store there the section number (1 in this case) the label belongs to:

...
\newlabel{interesting<1>}{{2}{3}{One\relax }{Doc-Start}{}}
...

So am I out of luck here?

Edit: I am now considering looking into the zref package to solve my problem. The challenge will probably be to get it integrated with the label=mylabel frame option, which implicitly generates those helpful "overlay" labels (mylabel<1>, mylabel<2>, ...) to refer to individual slides of a frame.

Any hints or ideas still are more than welcome :-)

share|improve this question
add comment

1 Answer

up vote 2 down vote accepted

The label key of the beamer frame uses the \label<> macro internally. This uses the normal \label macro of LaTeX which uses the \@currentlabel macro for the label text. This macro is set by \refstepcounter which is used by sectioning macros, captions and also frames. It uses the content of the corresponding \the... macro, so setting \theframenumber, not \insertframenumber is important.

Note that \insertframenumber is by default set to \@arabic\c@framenumber which is the lower-level version of \arabic{framenumber}, i.e. the default definition of \theframenumber. So my first step was to redefine \theframenumber and make \insertframenumber use it:

\renewcommand{\theframenumber}{\thesection-\arabic{framenumber}}
\renewcommand{\insertframenumber}{\theframenumber}

However, this doesn't work. After some debugging I found out that actually the subsectionslide counter is used for the label key. I have no idea why. Maybe the \refstepcounter{subsectionslide} is processed after the \refstepcounter{framenumber}. The related file is beamerbaseframe.sty. It doesn't like it in the code, but I don't had time to follow all the conditionals in it.

Anyway, the solution is to also(?) set \thesubsectionslide to \thesection-\arabic{framenumber} or \theframenumber. Then the references are displayed as you want. However, references to the subsectionslide (whatever this is exactly) might be wrong.

\documentclass{beamer}

\makeatletter
\renewcommand{\insertframenumber}{\theframenumber}
\renewcommand{\theframenumber}{\thesection-\arabic{framenumber}}
\renewcommand{\thesubsectionslide}{\thesection-\arabic{framenumber}}
\setbeamertemplate{headline}[text line]{This is frame: \insertframenumber}
\AtBeginSection{\setcounter{framenumber}{0}}

\begin{document}

\section{One}
\subsection{a}
\begin{frame}{First Frame in Section One}
  Slide content\par
  \pause
  More content
\end{frame}

\subsection{b}
\begin{frame}[label=interesting]{Second Frame in Section One -- The one to crossref to}
  Slide content
\end{frame}

\section{Two}
\begin{frame}{First Frame in Section Two}

  Now I want to crossref to interesting slide by section-framenumber (that is, somehow generate \textbf{1-2}) 
  \begin{itemize}
    \item \textbackslash{}ref yields: \ref{interesting}, apparently that is the frame number
    \item \textbackslash{}page yields: \pageref{interesting}, apparently that is the PDF page number
    \item \textbackslash{}autoref yields: \autoref{interesting}, apparently that is the frame number again
    \item nothing there that yields \textbackslash{}thesection of our target label?
  \end{itemize}
\end{frame}

\end{document}
share|improve this answer
    
Thanks a lot martin! –  Daniel Apr 9 '11 at 10:30
    
Thanks a lot Martin! I am on the jump so I cannot test your solution right now, but will do ASAP. The day before I also stumbled over the \refstepcounter{subsectionslide} issue, which (IMHO) makes no sense at all (should be \stepcounter): The framenumber returned by \ref is reset with every subsection, but the number inserted by \insertframenumber is not, so cross-ref to frames by number stops working when one uses subsections. This bug has been around for a while, I've applied the patch. –  Daniel Apr 9 '11 at 10:40
2  
The combination of Martin's answer (redefining \theframenumber and \insertframenumber and this patch to beamerbaseframe.sty works like a a charm. (@Martin : You might want to edit your answer in this respect.) The linked patch solves apparently a number of issues with respect to wrong reference counting by beamer, however, in my case it would also have been enough to change the first \refstepcounter{subsectionslide) in beamerbaseframe.sty to \stepcounter{subsectionslide}. –  Daniel Apr 9 '11 at 18:09
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.