47

I have a beamer presentation in which I have some additional slides in an appendix. The additional slides are only there in case someone asks a specific question; I won't necessarily have to use any of them.

I am using a theme that prints both the current frame number and the total number of frames on the bottom of each page. My problem is that the total number of frames includes all of the "extra" frames I have in the appendix. Let's say I have 20 "real" frames and then 5 additional frames in the appendix. The problem now is that \inserttotalframenumber (which is what the theme uses to print the total number of frames) returns 25. This is misleading to the audience because I may never even present any of the 5 additional frames.

The ideal behavior would be for \inserttotalframenumber to return 20, not 25. If I did advance to one of the appendix frames then I would like the frame to be "26/25", "27/25", and so on. How can this be done?

Edit:

I see that \inserttotalframenumber is defined in beamerbasemisc.sty by writing the value of the \c@framenumber counter to the .aux file at the end of the document. I guess one way to achieve my desired behavior is to do something like

\AtEndDocument{
  \immediate\write\@auxout{\string\@writefile{nav}%
    {\noexpand\headcommand{\noexpand\def\noexpand\inserttotalframenumber{\insertframenumber}}}}
}

on the last "real" slide of my document. That seems like a bit of a hack though. Is there a better way?

  • 5
    A slight non sequitur: one of my professors told me never to include the total number of slides in a presentation, because "it will only cause you dread [of running out of time], and the audience despair [of the never ending presentation]". He also said that a good presenter should "know where he is in the talk without referring to a silly number". – Willie Wong Aug 30 '10 at 19:57
  • 1
    @WillieWong I disagree. An someone in the audience, I would like to know where we are in the presentation and be able to form my expectation of how much material will follow (and basing on that also form expectation of the kind of materials to follow). The total page count helps. – Fang Jing Nov 11 '16 at 18:54
  • 1
    The appendixnumberbeamer package performs a related function. It automatically counts only the number of frames before the appendix (and put only the total number of these frames before the appendix), and then restart the a separate count for the appendix frames (and put only the total number of appendix frames in the appendix). – Fang Jing Nov 11 '16 at 19:14
  • @FangJing: unless you are talking about an extended presentation that spans multiple sessions over multiple days, why is "wearing a watch" not a solution to your problem? – Willie Wong Nov 11 '16 at 20:40
  • 1
    @WillieWong Wearing a watch only tells the time left, not the number of slides left. I think they provide different perspectives on the remaining materials. – Fang Jing Nov 29 '16 at 19:05
41

I've used the following macros for this purpose:

\newcommand{\backupbegin}{
   \newcounter{framenumberappendix}
   \setcounter{framenumberappendix}{\value{framenumber}}
}
\newcommand{\backupend}{
   \addtocounter{framenumberappendix}{-\value{framenumber}}
   \addtocounter{framenumber}{\value{framenumberappendix}} 
}

The bonus slides are then put between the two commands:

\appendix
\backupbegin

\frame{\frametitle{One more thing}}

\backupend

This will get you the desired numbering, too.

16

You can enable the (undocumented) noframenumbering option for each frame in the appendix. This also works for omitting the title page in the frame total.

\begin{document}
\begin{frame}[plain,noframenumbering]
  \titlepage
\end{frame}
...
\appendix
\begin{frame}[noframenumbering]
  ...
\end{frame}
\end{document}

Unfortunately this setting isn't inherited by additional frames resulting from allowframebreaks. To fix this, add the following to your preamble.

\usepackage{etoolbox}
\makeatletter
\preto{\appendix}{%
  \patchcmd{\beamer@continueautobreak}{\refstepcounter{framenumber}}{}{}{}}
\makeatother
  • Interesting! This is much less of a hack than my version. +1 – ESultanik Apr 25 '13 at 12:48
10

I had the same problem and found the answer on stackoverflow.

The answer is very simple, just include the appendixnumberbeamer package:

\usepackage{appendixnumberbeamer}
8

You could use the standard referencing features and redefine \inserttotalframenumber right after \begin{document} (not before):

\renewcommand*{\inserttotalframenumber}{\pageref{lastframe}}

In the last frame, before your appendix, set the label:

\begin{frame}\label{lastframe}
...
\end{frame}
% now your appendix frames follow

If you set the lastframe label on frame 20 and let 5 frames follow, an infolines theme would show "4 / 20" and so on. The last appendix frame would show "25 / 20" like desired.

  • This approach will only work if every frame only has a single overlay. The problem is that \pageref refers to the page number of the last frame, not the frame number. Therefore, if any of the previous frames take up multiple pages in the PDF, the \pageref will return the wrong number. – ESultanik Aug 30 '10 at 20:19
1

Inspired by Stefan's answer, here is the solution up with which I ended (which rectifies the problem of using \pageref):

Immediately before \appendix I added this:

\makeatletter
  \immediate\write\@mainaux{\string\gdef\string\inserttotalframenumbernew{\insertframenumber}}
\makeatother

That writes the number of the last "real" frame to the .aux file as the new command \inserttotalframenumbernew. Then, at the beginning of my document, I added this:

\makeatletter
  \@ifundefined{inserttotalframenumbernew}{
    \gdef\inserttotalframenumbernew{1}
  }{}
  \gdef\inserttotalframenumber{\inserttotalframenumbernew}
\makeatother

That redefines \inserttotalframenumber to be the value of \inserttotalframenumbernew (which is read from the .aux).

This still feels like a bit of a hack to me, though. It would be a lot cleaner if beamer had a macro that acted like \pageref but instead returned a frame number, but beamer doesn't seem to.

1

I've dealt with this by making two distinct pdfs and then pasting them together with the command line tool pdftk. Not fancy, but it works. (That said, I will be trying the solution @ESultanik ended up with if ever this comes up again.)

1

The great command \insertpresentationendpage will take care of your problem. Just place \appendix at the begin of your backup slides.

\documentclass[t]{beamer}

\usepackage[absolute,overlay]{textpos}
\setbeamertemplate{navigation symbols}{}

\setbeamertemplate{footline}{%
    \begin{picture}(54,12.5)(0,0)
    \put(0.9,0.52){%
        \begin{minipage}[b][12.5mm][c]{112.5mm}
        \raggedleft
        \insertpagenumber/\insertpresentationendpage
        \end{minipage}
    }
    \end{picture}
}


\begin{document}

    \begin{frame}
        slide in the main part
    \end{frame}

    \appendix
    \section*{Backup}

    \begin{frame}
        \frametitle{backup}
        not counting in the total frame number
    \end{frame}

\end{document}

enter image description here


Edit:

As David Z pointed out in his comment, this does not work when using overlays. The following workaround (stolen from diabonas answer) takes care of this problem:

\documentclass[t]{beamer}

\usepackage[absolute,overlay]{textpos}
\setbeamertemplate{navigation symbols}{}

\def\insertpresentationendframe{\inserttotalframenumber}
\makeatletter
\g@addto@macro{\appendix}{\immediate\write\@auxout{\string\@writefile{nav}{\noexpand\headcommand{\noexpand\def\noexpand\insertpresentationendframe{\the\c@framenumber}}}}}
\makeatother

\setbeamertemplate{footline}{%
    \begin{picture}(54,12.5)(0,0)
    \put(0.9,0.52){%
        \begin{minipage}[b][12.5mm][c]{112.5mm}
        \raggedleft
        \insertframenumber/\insertpresentationendframe
        \end{minipage}
    }
    \end{picture}
}

\begin{document}

    \begin{frame}
        slide in the main part
    \end{frame}

    \begin{frame}
        a frame with overlays
        \begin{onlyenv}<1>
            overlay1
        \end{onlyenv}
        \begin{onlyenv}<2>
            overlay2
        \end{onlyenv}
    \end{frame}

    \appendix
    \section*{Backup}

    \begin{frame}
        \frametitle{backup}
        not counting in the total frame number
    \end{frame}

\end{document}

NEW

Starting with beamer version >= 3.49 many of the default themes can automatically number the appendix separately if \setbeamertemplate{page number in head/foot}[appendixframenumber] is used after the theme.

MWE:

\documentclass{beamer}
\usetheme{Madrid}

\setbeamertemplate{page number in head/foot}[appendixframenumber]

\begin{document}
\begin{frame}
  \frametitle{First slide}
\end{frame}

\appendix

\begin{frame}
content...
\end{frame}

\end{document}
  • Unfortunately this doesn't work when there are frames with multiple slides (i.e. if you use overlays): it counts the number of slides, not the number of frames. – David Z Jan 17 '14 at 9:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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