# Reset frame number and total frame count per Beamer section

I'm using a LaTeX Beamer frame counter that displays

\insertframenumber/\inserttotalframenumber


... which would mean that if my project has twenty frames and the slideshow is on the sixteenth frame, "16/20" is displayed.

My project contains very long sections (they mirror book chapters), and I want the frames of each section to have a counter local to that section.

For example, if that sixteenth frame is actually in section 2, and section 1 had 5 frames, then it should show "11/15".

Maybe there's a solution with \AtBeginSection, but I doubt it, since there would be no good way of calculating \inserttotalframenumber to my knowledge.

If it helps, here's an MWE of my current setup (with fewer frames):

%%% Preamble %%%
\documentclass{beamer}
\usetheme{Antibes}
\usebeamercolor{dolphin}

% Make slide numbers appear, and they appear next to navigation
\usebeamerfont{footline}%
\usebeamercolor[fg]{footline}%
\hspace{1em}%
}

%%% Document %%%
\begin{document}

\section{First section}

\begin{frame}
\frametitle{First}
This frame should show 1/2'', not 1/5''.
\end{frame}

\begin{frame}
\frametitle{Second}
This frame should show 2/2'', not 2/5''.
\end{frame}

\section{Second section}

\begin{frame}
\frametitle{Third}
This frame should show 1/3'', not 3/5''.
\end{frame}

\begin{frame}
\frametitle{Fourth}
This frame should show 2/3'', not 4/5''.
\end{frame}

\begin{frame}
\frametitle{Fifth}
This frame should show 3/3'', not 5/5''.
\end{frame}

\end{document}

• It would really help the community if you could provide us with a complete, minimal example that replicates your current setup. Something with a couple of sections with different frame counts. Can you do that?
– Werner
Aug 18, 2021 at 1:40
• @Werner I have added the bare minimum setup below the question.
– Mew
Aug 18, 2021 at 10:51

The following approach inserts a "label" into the .aux at every \section (including at the end of the document) in order to capture the current frame number. This captured frame number (which resets with every \section thanks to chngcntr) is then inserted in the footer.

\documentclass{beamer}

\usetheme{Antibes}
\usebeamercolor{dolphin}

\usepackage{chngcntr}

% Make slide numbers appear, and they appear next to navigation
\usebeamerfont{footline}%
\usebeamercolor[fg]{footline}%
\hspace{1em}%
}

\makeatletter
\let\oldsection\section
\renewcommand{\section}{% Store current \section's frame count
\oldsection
}
\AtEndDocument{% Store final \section's frame count
}
\makeatother

\begin{document}

\section{First section}

\begin{frame}
\frametitle{First}
This frame shows 1/2'', not 1/5''.
\end{frame}

\begin{frame}
\frametitle{Second}
This frame shows 2/2'', not 2/5''.
\end{frame}

\section{Second section}

\begin{frame}
\frametitle{Third}
This frame shows 1/3'', not 3/5''.
\end{frame}

\begin{frame}
\frametitle{Fourth}
This frame shows 2/3'', not 4/5''.
\end{frame}

\begin{frame}
\frametitle{Fifth}
This frame shows 3/3'', not 5/5''.
\end{frame}

\end{document}

• It's kind of baffling to me that you had to put in non-trivial work to do this, as I'd expect Beamer to just have this built in. Great work.
– Mew
Aug 18, 2021 at 17:26
• @Mew: The total frame number count is just a label that is stored at the end of the document. So in order to capture the per-section frame total you have to flex some other muscles. I'm sure there might be a more beamer-ish way, but my approach seems to work as expected.
– Werner
Aug 18, 2021 at 17:32