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}
The Dreden theme uses as outer theme miniframes
specifying that the footline is of type authorinstitutetitle
\useoutertheme[footline=authorinstitutetitle]{miniframes}
Thus, to insert the frame number (command \insertframenumber
) with respect to the total frame number (command \inserttotalframenumber
) we should take into account how the authorinstitutetitle
is defined:
\def\beamer@theme@footline@authorinstitutetitle{
\defbeamertemplate*{footline}{miniframes theme}
{%
\begin{beamercolorbox}[colsep=1.5pt]{upper separation line foot}
\end{beamercolorbox}
\begin{beamercolorbox}[ht=2.5ex,dp=1.125ex,%
leftskip=.3cm,rightskip=.3cm plus1fil]{author in head/foot}%
\leavevmode{\usebeamerfont{author in head/foot}\insertshortauthor}%
\hfill%
{\usebeamerfont{institute in head/foot}\usebeamercolor[fg]{institute in head/foot}\insertshortinstitute}%
\end{beamercolorbox}%
\begin{beamercolorbox}[ht=2.5ex,dp=1.125ex,%
leftskip=.3cm,rightskip=.3cm plus1fil]{title in head/foot}%
{\usebeamerfont{title in head/foot}\insertshorttitle}%
\end{beamercolorbox}%
\begin{beamercolorbox}[colsep=1.5pt]{lower separation line foot}
\end{beamercolorbox}
}
}
Now, in the lower right corner there's nothing thus it is possible to exploit the space in:
\begin{beamercolorbox}[ht=2.5ex,dp=1.125ex,%
leftskip=.3cm,rightskip=.3cm plus1fil]{title in head/foot}%
{\usebeamerfont{title in head/foot}\insertshorttitle}%
\end{beamercolorbox}%
by adding:
\begin{beamercolorbox}[ht=2.5ex,dp=1.125ex,%
leftskip=.3cm,rightskip=.3cm plus1fil]{title in head/foot}%
{\usebeamerfont{title in head/foot}\insertshorttitle}%
\hfill%
{\usebeamerfont{frame number}\usebeamercolor[fg]{frame number}\insertframenumber~\frameofframes~\inserttotalframenumber}
Notice that as separator between the frame numbers there's a command: \frameofframes
. It is defined as:
\newcommand{\frameofframes}{/}
\newcommand{\setframeofframes}[1]{\renewcommand{\frameofframes}{#1}}
This allows you to modify the standard representation (1/5
for example), with something else; for instance:
\setframeofframes{of}
will provide 1 of 5
.
The code:
\documentclass{beamer}
\usepackage{lmodern}
\usetheme{Dresden}
\author{My name}
\title{My presentation}
\institute{My institute}
\newcommand{\frameofframes}{/}
\newcommand{\setframeofframes}[1]{\renewcommand{\frameofframes}{#1}}
\setframeofframes{of}
\makeatletter
\setbeamertemplate{footline}
{%
\begin{beamercolorbox}[colsep=1.5pt]{upper separation line foot}
\end{beamercolorbox}
\begin{beamercolorbox}[ht=2.5ex,dp=1.125ex,%
leftskip=.3cm,rightskip=.3cm plus1fil]{author in head/foot}%
\leavevmode{\usebeamerfont{author in head/foot}\insertshortauthor}%
\hfill%
{\usebeamerfont{institute in head/foot}\usebeamercolor[fg]{institute in head/foot}\insertshortinstitute}%
\end{beamercolorbox}%
\begin{beamercolorbox}[ht=2.5ex,dp=1.125ex,%
leftskip=.3cm,rightskip=.3cm plus1fil]{title in head/foot}%
{\usebeamerfont{title in head/foot}\insertshorttitle}%
\hfill%
{\usebeamerfont{frame number}\usebeamercolor[fg]{frame number}\insertframenumber~\frameofframes~\inserttotalframenumber}
\end{beamercolorbox}%
\begin{beamercolorbox}[colsep=1.5pt]{lower separation line foot}
\end{beamercolorbox}
}
\makeatother
\begin{document}
\section{One}
\subsection{One-one}
\frame{\frametitle{X-one} bla bla bla}
\frame{\frametitle{X-one-a} bla bla bla}
\frame{\frametitle{X-one-b} bla bla bla}
\subsection{One-two}
\frame{\frametitle{X-one} bla bla bla}
\frame{\frametitle{X-one-a} bla bla bla}
\frame{\frametitle{X-one-b} bla bla bla}
\section{Two}
\subsection{Two-one}
\frame{\frametitle{X-one} bla bla bla}
\frame{\frametitle{X-one-a} bla bla bla}
\frame{\frametitle{X-one-b} bla bla bla}
\subsection{Two-two}
\frame{\frametitle{X-one} bla bla bla}
\frame{\frametitle{X-one-a} bla bla bla}
\frame{\frametitle{X-one-b} bla bla bla}
\section{Three}
\subsection{Three-one}
\frame{\frametitle{X-one} bla bla bla}
\frame{\frametitle{X-one-a} bla bla bla}
\frame{\frametitle{X-one-b} bla bla bla}
\subsection{Three-two}
\frame{\frametitle{X-one} bla bla bla}
\frame{\frametitle{X-one-a} bla bla bla}
\frame{\frametitle{X-one-b} bla bla bla}
\end{document}
One frame as result:
Best Answer
Here's one possible solution:
An image showing the produced cross-references:
The idea is simply to set the
framenumber
counter to be prepended by thepart
counter. I used a similar mechanism as the used byamstex
's\numberwithin
, but with a variation to use a hyphen instead of a dot. Provision was made to make this change just after a\part
command has been actually used so eventual references to frames before the first part will produce just the frame number.Notice that with these settings, there's no need for your \slidenumber command, since now you can simply use \theframenumber: