4

Consider the following beamer example below. Is it possible to adjust this, that Frame 4 has framenumber 3 on the handout (and not 4 in my example). In other words the numbering in the handout should be as the code of frame 3 would be commented out (and not just have the option ).

\documentclass[handout,gray]{beamer}
\usepackage[utf8]{inputenc}

\usepackage{pgfpages}
\pgfpagesuselayout{4 on 1}[a4paper,border shrink=5mm,landscape]

\setbeamertemplate{headline}{\scriptsize{\vspace*{0.3cm}\hspace*{0.3cm}\insertframenumber}}


\begin{document}


\begin{frame}
   \frametitle{Frame 1}
   Frame 1
\end{frame}

\begin{frame}<display:0>
   \frametitle{Frame 2}
   Frame 2
\end{frame}

\begin{frame}<handout:0>
   \frametitle{Frame 3}
   Frame 3
\end{frame}

\begin{frame}
   \frametitle{Frame 4}
   Frame 4
\end{frame}   
\end{document}

Frames

student
  • 29,003
  • I'm not sure I really understand. In your example, the numbers are hard-coded (not automatically generated) so you could do something like \alt<display>{4}{3} to put a 4 when in display mode and 3 otherwise (ie handout mode, though article would also get the 3). Would this help, or is the real case more complicated? – Andrew Stacey Mar 26 '12 at 19:57
  • @AndrewStacey The real example has a lot more frames and a lot more frames which should be skipped for the handout. So it's not a good idea to generate the framenumbers manually for the handout. Note that I don't need any numbers for display. I just want to have consecutive numbering for the handout frames (1,2,3,4,... without skipping a number though some frames are not on the handout). – student Mar 27 '12 at 14:33

1 Answers1

7

Since beamer version 3.08, there is an undocumented option noframenumbering that doesn't increase the slide counter for the current frame. So if you want to exclude a single frame from the numeration and the handout, you can use

\begin{frame}<handout:0>[noframenumbering]
  ...
\end{frame}

To automate this, i. e. to exclude all the frame that aren't displayed in the current mode (handout, trans) from the numeration, you can patch the internal beamer command responsible for generating the frames:

\usepackage{etoolbox}
\makeatletter
\pretocmd{\beamer@@@@frame}{\alt<#1>{}{\beamer@noframenumberingtrue}}{}{}
\makeatother

Include this code somewhere in the preamble (that's between \documentclass{beamer} and \begin{document}) of your document. It uses the overlay command \alt to activate noframenumbering on every slide which isn't displayed.

Example code:

\documentclass[handout,gray]{beamer}
\usepackage[utf8]{inputenc}

\usepackage{pgfpages}
\pgfpagesuselayout{4 on 1}[a4paper,border shrink=5mm,landscape]

\setbeamertemplate{headline}{\scriptsize{\vspace*{0.3cm}\hspace*{0.3cm}\insertframenumber}}

% https://tex.stackexchange.com/a/49806/3323
\usepackage{etoolbox}
\makeatletter
\pretocmd{\beamer@@@@frame}{\alt<#1>{}{\beamer@noframenumberingtrue}}{}{}
\makeatother

\begin{document}
\begin{frame}
    Absolute frame number: 1\\
    Frame number in presentation: \insertframenumber
\end{frame}
\begin{frame}
    Absolute frame number: 2\\
    Frame number in presentation: \insertframenumber
\end{frame}
\begin{frame}<handout:0>
    Absolute frame number: 3\\
    Frame number in presentation: \insertframenumber
\end{frame}
\begin{frame}
    Absolute frame number: 4\\
    Frame number in presentation: \insertframenumber
\end{frame}
\end{document}

Result (click on the image to see it full-size):

output of the example handout with continuous frame numbering

David Carlisle
  • 757,742
diabonas
  • 25,784
  • This looks like a wonderful answer, however I have a slight doubt about the details, given that \pretocmd is suppoesed (per the etoolbox documentation) to take 4 arguments. Are you sure you did not mismatch your braces? – Circonflexe Oct 04 '16 at 12:45
  • Answering my own comment: I fixed your solution in the following way: \pretocmd{\beamer@@@@frame}{\alt<#1>{}{\beamer@noframenumberingtrue}}{}{}}%. Of course, this does not work in a macro (because it does not like the #). The usual trick (which I just tested and it works) is then to do something like \def\hideInvisible{\lccode\~=`#\lowercase{% \pretocmd{\beamer@@@@frame}{\alt<~1>{}{\beamer@noframenumberingtrue}}{}{}}% \lccode`~=0}(Doubling the#` did not work for me). – Circonflexe Oct 04 '16 at 13:18
  • 1
    @Circonflexe You are right, \pretocmd has two further arguments to execute code when patching succeeds or fails. I did not notice the error as the code compiles as is, using \makeatother as the code for success and the following empty line (equivalent to a \par) as the code for failure. Thank you for the hint, I have updated the answer to use \pretocmd correctly. – diabonas Oct 04 '16 at 13:18
  • As of Feb 2023, is the patch with \pretocmd still working for you? It used to work for me, but doesn't anymore... maybe I have messed up something? – PatrickT Feb 08 '23 at 20:00