# LaTeX Beamer: How to get distinct page numbers when using overlays?

## The question

When I create slides for presentations in LaTeX with the Beamer class, I like to use constructions with overprint like this:

\begin{frame}
\begin{block}{}
\begin{itemize}
\item Some general remarks about ALL plots
\end{itemize}
\end{block}
\begin{block}{}
\begin{center}
\begin{overprint}
\only<+>{
\incgraphics{width=7cm}{plot1.pdf}\\
Explanation of Figure 1
}
\only<+>{
\incgraphics{width=7cm}{plot2.pdf}\\
Explanation of Figure 2
}
% maybe more plots...
\end{overprint}
\end{center}
\end{block}
\end{frame}


The problem is that like this all slides created from one frame are assigned the same page number which makes people complain that it's difficult to follow which slide I am on (when giving the talk via phone etc.).

How can I change this?

## A minimal example to reproduce the problem

\documentclass{beamer}

\begin{document}

\begin{frame}
Common text\\
\begin{overprint}
\only<+>{
Figure 1 and explanation of Figure 1
}
\only<+>{
Figure 2 and explanation of Figure 2
}
\end{overprint}
\end{frame}

\end{document}


One can mess around with \setbeamertemplate and use \insertpagenumber{} instead of \insertframenumber{}, but like this you lose generality (e.g. you cannot switch between themes easily).

Maybe there is a better solution?

-
I use \setbeamertemplate{footline}{\hfill\large\insertpagenumber} –  Konrad Swanepoel Oct 12 '10 at 5:34

Good question. There seems to be no built-in functionality to do what you want. There must be a counter that holds the slide number, but the manual doesn't seem to expose it and I don't want to delve into the source.

My solution might be classified as "messing around", but here goes:

\documentclass{beamer}
\newcounter{slidenumber}

\defbeamertemplate*{footline}{infolines theme frame plus slide}{
\setcounter{slidenumber}{\insertpagenumber}%
\leavevmode%
\hbox{%
\end{beamercolorbox}%
\end{beamercolorbox}%
\end{beamercolorbox}}%
\vskip0pt%
}

\setbeamertemplate{footline}[infolines theme frame plus slide]

\begin{document}
\begin{frame}
Common text\\
\begin{overprint}
\only<+>{
Figure 1 and explanation of Figure 1
}
\only<+>{
Figure 2 and explanation of Figure 2
}
\end{overprint}
\end{frame}

\begin{frame}
Common text on frame 2\\
\begin{overprint}
\only<+>{
Figure 1 and explanation of Figure 1
}
\only<+>{
Figure 2 and explanation of Figure 2
}
\end{overprint}
\end{frame}

\end{document}


Any theme which uses the infolines inner theme can thus be modified. If you didn't want to touch any templating, you could redefine \insertframenumber to return the frame number . slide number, but I don't know if that's going to break anything else.

-
I have played around with redefining \insertframenumber before; if I recall correctly, it does have the potential to break things (especially if you are using hyperlinks between frames). –  ESultanik Nov 19 '10 at 18:49

The number of the current slide within the frame is stored in the TeX count register \beamer@slideinframe. You could turn it into a LaTeX counter with

\makeatletter
\setcounter{currentslide}{\the\beamer@slideinframe}
\makeatother


if you like.

-
I would rather use \makeatletter\def\c@slideinframe{\beamer@slideinframe}\makeatother to create an LaTeX counter alias named slideinframe (or using another name) which is always in sync with the internal beamer counter. However, the issue is that the counter doesn't hold the correct value inside the footer. I always get 2 for both slides. –  Martin Scharrer May 11 '11 at 15:08

I had this same question and approached it using the built-in beamer macros \insertpagenumber and \insertsectionendpage or \insertpresentationendpage to show the current page number out of the total number of pages in the section, or presentation respectively. The page number is incremented using overlays, while the frame number is not. You can use this command within footlines. An MWE is below. I know this question is old but it took me a while to find these commands so I wanted to draw attention to them.

\documentclass{beamer}

\setbeamertemplate{footline}{% set footline options
\insertpagenumber/\insertsectionendpage
}

\begin{document}

\begin{frame}
Common text\\
Page - \insertpagenumber{} of \insertpresentationendpage \\
\begin{overprint}
\only<+>{
Figure 1 and explanation of Figure 1
}
\only<+>{
Figure 2 and explanation of Figure 2
}
\end{overprint}
\end{frame}

\end{document}


-

I would think the easiest way is to avoid the overprint environment altogether:

\documentclass{beamer}

\begin{document}

\begin{frame}
Common text\\
\includegraphics{fig1.png} \\
Figure 1 and explanation of Figure 1
\end{frame}
\begin{frame}
Common text\\
\includegraphics{fig2.png} \\
Figure 2 and explanation of Figure 2
}
\end{frame}

\end{document}


This will give you two identical slides, but with different figures and different slide numbers. The only issue that I can think of is that compiling the handout mode will not work properly.

-

I am not sure, if this is exactly what you want, but you could also use \begin{frame} and \againframe with labels and overlay specifications:

\documentclass{beamer}

\begin{document}

\begin{frame}<1>[label=somelabel]
Common text\\
\begin{overprint}
\only<+>{
Figure 1 and explanation of Figure 1
}
\only<+>{
Figure 2 and explanation of Figure 2
}
\end{overprint}
\end{frame}

\againframe<2>{somelabel}

\end{document}


With this solution you can at least choose which overlays should have the same frame number and which not.

-

I came upon this solution while searching for the opposite problem---combining the \visible command with a custom footer defined using page number creates separate slide numbers for additional text on the same frame.

This is a similar answer to one above, but using a different way to display text/figures, so I thought I'd include it as well.

\documentclass{beamer}

\defbeamertemplate{footline}{centered page number}
{
\hspace*{\fill}  %Put page counter on the right
\usebeamercolor[fg]{page number in head/foot} %Color the page number
\usebeamerfont{page number in head/foot} %Change the font for page number
%======Choose one of the following two options=====%
\insertpagenumber\,/\,\insertpresentationendpage %Manually style page number out of total pages
%\insertpagenumber\, %Manually style page number only
%==================================================%
\hspace*{.3cm}\vskip8pt  %Move the page counter slightly
}
\setbeamertemplate{footline}[centered page number]

\begin{document}

\begin{frame}
This text is always visible
\visible<2>{New text now available on the same frame, but counted as second slide; only available second showing of slide}

\visible<3>{\includegraphics{Images/foo.png}

This image (and text) only present on the third showing on slide; counted as a third slide number. }
\end{frame}

\end{document}

-