27

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}

\usetheme{Madrid}

\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}

Partial answer

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?

1
  • I use \setbeamertemplate{footline}{\hfill\large\insertpagenumber} Oct 12, 2010 at 5:34

8 Answers 8

8

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}
\usetheme{Madrid}
\newcounter{slidenumber}

\defbeamertemplate*{footline}{infolines theme frame plus slide}{
    \setcounter{slidenumber}{\insertpagenumber}%
    \addtocounter{slidenumber}{-\insertframestartpage}%
    \addtocounter{slidenumber}{1}%
    \leavevmode%
    \hbox{%
        \begin{beamercolorbox}[wd=.333333\paperwidth,ht=2.25ex,dp=1ex,center]{author in head/foot}%
            \usebeamerfont{author in head/foot}\insertshortauthor~~(\insertshortinstitute)
        \end{beamercolorbox}%
        \begin{beamercolorbox}[wd=.333333\paperwidth,ht=2.25ex,dp=1ex,center]{title in head/foot}%
            \usebeamerfont{title in head/foot}\insertshorttitle
        \end{beamercolorbox}%
        \begin{beamercolorbox}[wd=.333333\paperwidth,ht=2.25ex,dp=1ex,right]{date in head/foot}%
            \usebeamerfont{date in head/foot}\insertshortdate{}\hspace*{2em}
            \insertframenumber.\arabic{slidenumber}{}/ \inserttotalframenumber\hspace*{2ex} 
        \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.

1
  • 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, 2010 at 18:49
12

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}

\usetheme{Madrid}

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

\begin{document}

\begin{frame}
  Common text\\
  Frame - \insertframenumber{} of \inserttotalframenumber \\
  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}

frame1 frame2

0
10

Although the question is very old, I think I might contribute. Just increase the frame number manually by one, each time it is needed. Do this by writing \addtocounter{framenumber}{1} Be sure you do this within the scope of an \only{}, otherwise it will apply to all the slides. And be sure it is the correct \only{}. Your MWE can be modified as:

\documentclass{beamer}

\usetheme{Madrid}

\begin{document}

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

\end{document}

This will also increase your total page count.

Let's make it clear, because it is important: it MUST be within an \only{}, using \onslide or \pause is not enough, only \only{} ensures the code is NOT executed in the other slides. If you are acheving the overlays using means other than \only{}, in the worst case you can just add a series of \only{} with the exact page numbers, like:

\only<2>{\addtocounter{framenumber}{1}}
\only<3>{\addtocounter{framenumber}{1}}
\only<4>{\addtocounter{framenumber}{1}}

and so on.


EDIT:

rather than \addtocounter{framenumber}{1}, you can directly use \stepcounter{framenumber}. Further, to have each slide numbered as a separate frame, rather than inserting the whole sequence as I pointed out above you can write:

\only<2-|handout:0>{\stepcounter{framenumber}}

because this command is applied on every slide after the first one. I added handout:0 to avoid a mess for handout mode.


SO, IN SUMMARY:

If you want to have all slides numbered as separate frames, just add \only<2-|handout:0>{\stepcounter{framenumber}} at the top and you'll be fine. Just be careful to use it only where you are ACTUALLY using overlays, because otherwise the \only<2-> will cause an overlay and the frame will be duplicated in two identical slides.

1
  • Works. Like. Magic! Also, so elegant, many thanks, @Gabriele B :-)
    – s0nata
    Dec 27, 2017 at 11:00
6

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.

1
  • 5
    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. May 11, 2011 at 15:08
5

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}

\usetheme{Madrid}

\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.

1

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}

\setbeamertemplate{navigation symbols}{}  %Turn off navigation sybols
\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}
1

A very simple solution is to place the \addtocounter{framenumber}{1} somewhere in the "common" space of the frame. Verytime the frame is read, the counter is increased. Of course beamer itself increases the counter one time too, so we have to undo one increase.

\documentclass{beamer}

\usetheme{Madrid}

\begin{document}

\addtocounter{framenumber}{-1}
\begin{frame}
\addtocounter{framenumber}{1}

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}

enter image description here

1

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

\documentclass{beamer}

\usetheme{Madrid}

\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.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .