4

I am trying to put together a beamer document put together using multiple sections where frame numbers restart at each section and I can leave certain frames at the beginning of the document and at the beginning of each section uncounted.

My master document looks like this:

\documentclass{beamer}

\mode<presentation>
{
\usetheme{default} 
\usecolortheme{default}
\usefonttheme{default} 
\setbeamertemplate{navigation symbols}{}
\setbeamertemplate{caption}[numbered]
 \setbeamertemplate{footline}[frame number]
}

\AtBeginSection{\setcounter{framenumber}{0}}

\usepackage{hyperref}

\title[MATH]{Daily Notes}
\author{Me}
\institute{My College}
\date{\today}

\begin{document}
{
\setbeamertemplate{footline}{}
\begin{frame}[noframenumbering]
\titlepage
\end{frame}
}

{
\setbeamertemplate{footline}{}
\begin{frame}[noframenumbering]{Table of Contents}
\setcounter{tocdepth}{1}
\label{ToC}
\tableofcontents
\end{frame}
}

\input{Day_1.tex}
\input{Day_2.tex}

\end{document}

I use hyperref to create links in the table of contents. The two input files are comparable except in the number of frames and that seems to be the trouble. If Day_1.tex has 4 frames like so:

\section{The First}
\subsection{Housekeeping}

{
\setbeamertemplate{footline}{}
\begin{frame}[noframenumbering]{Announcements}
Hello world!
\end{frame}
}

\subsection{Content}
\begin{frame}
First slide
\end{frame}

\begin{frame}
Second slide
\end{frame}

\begin{frame}
Third slide
\end{frame}

\begin{frame}
Fourth slide
\end{frame}

and Day_2.tex is the same except having only 3 frames, then the numbering for Day_1 is given as 1/3, 2/3, 3/3, 4/3. If Day_1 has fewer frames than Day_2 (say 2 for Day_1 and 3 for Day_2), then Day_1's numbering is given as 1/3, 2/3.

How can I get the correct number of frames for each section in the frame numbering?

1

The following answer is based on https://tex.stackexchange.com/a/279364/36296

The problem with your approach is that \totalframenumber is saved at the end of the document, so in your case it is the length of your last section. But instead you can calculate the length of each section.

\documentclass{beamer}

\usepackage{etoolbox}
\makeatletter
\newcount\beamer@sectionstartframe
\beamer@sectionstartframe=1
\apptocmd{\beamer@section}{\addtocontents{nav}{\protect\headcommand{%
            \protect\beamer@sectionframes{\the\beamer@sectionstartframe}{\the\c@framenumber}}}}{}{}
\apptocmd{\beamer@section}{\beamer@sectionstartframe=\c@framenumber\advance\beamer@sectionstartframe by1\relax}{}{}
\AtEndDocument{\immediate\write\@auxout{\string\@writefile{nav}%
        {\noexpand\headcommand{\noexpand\beamer@sectionframes{\the\beamer@sectionstartframe}{\the\c@framenumber}}}}}{}{}
\def\beamer@startframeofsection{1}
\def\beamer@endframeofsection{1}
\def\beamer@sectionframes#1#2{%
    \ifnum\c@framenumber<#1%
    \else%
    \ifnum\c@framenumber>#2%
    \else%
    \gdef\beamer@startframeofsection{#1}%
    \gdef\beamer@endframeofsection{#2}%
    \fi%
    \fi%
}
\newcommand\insertsectionstartframe{\beamer@startframeofsection}
\newcommand\insertsectionendframe{\beamer@endframeofsection}
\makeatother

\usepackage{tikz}
\usetikzlibrary{calc}

\def\inserttotalsectionframenumber{%
    \pgfmathparse{(\insertsectionendframe-\insertsectionstartframe+1)}%
    \pgfmathprintnumber[fixed,precision=2]{\pgfmathresult}%
}

\def\insertsectionframenumber{%
    \pgfmathparse{(\insertframenumber-\insertsectionstartframe+1)}%
    \pgfmathprintnumber[fixed,precision=2]{\pgfmathresult}%
}

\setbeamertemplate{footline}{\insertsectionframenumber/\inserttotalsectionframenumber}

\title[MATH]{Daily Notes}
\author{Me}
\institute{My College}
\date{\today}

\begin{document}
{
\setbeamertemplate{footline}{}
\begin{frame}[noframenumbering]
\titlepage
\end{frame}
}

{
\setbeamertemplate{footline}{}
\begin{frame}[noframenumbering]{Table of Contents}
\setcounter{tocdepth}{1}
\label{ToC}
\tableofcontents
\end{frame}
}

\section{The First}
\subsection{Housekeeping}

{
    \setbeamertemplate{footline}{}
    \begin{frame}[noframenumbering]{Announcements}
        Hello world!
    \end{frame}
}

\subsection{Content}
\begin{frame}
    First slide
\end{frame}

\begin{frame}
    Second slide
\end{frame}

\begin{frame}
    Third slide
\end{frame}

\begin{frame}
    Fourth slide
\end{frame}

\section{The Second}
\subsection{Housekeeping}

{
    \setbeamertemplate{footline}{}
    \begin{frame}[noframenumbering]{Announcements}
        Hello world!
    \end{frame}
}

\subsection{Content}
\begin{frame}
    First slide
\end{frame}

\begin{frame}
    Second slide
\end{frame}

\begin{frame}
    Third slide
\end{frame}

\end{document}
  • Thanks @samcarter. This seems like it should work but now I get an error I can't track down: Argument of \addtocontents has an extra }. <inserted text> \par – Brian Jan 5 '16 at 22:53
  • @Brian Strange. I checked again and I works fine for me. I am on TeXlive2015. – user36296 Jan 5 '16 at 23:38
  • @Brian Could you solve the problem? – user36296 Jan 11 '16 at 20:29
  • Unfortunately, no. Could it be due to the fact I'm using hyperref, as in (tex.stackexchange.com/questions/194720/…)? – Brian Jan 22 '16 at 18:10
  • Beamer itself should load hyperref by default. Can you check if the above code without modifications runs on your system? Or edit your question to show the code you tried? – user36296 Jan 22 '16 at 19:59

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.