2

I want a frametitle that contains the name of the current subsection, followed by a counter that starts at 1 and increases for every new frame in the current subsection.

I found the following solution somwhere, but my problem is that this counter also increases when I use any form of overlays.

Does someone know how to create a counter that only increases per frame and not per slide? Thanks in advance!

\documentclass{beamer}

% Subsection counter:
\newcounter{stappen}
\newcommand{\snumreset}{\setcounter{stappen}{0}}
\newcommand{\snum}{\stepcounter{stappen} \Roman{stappen}}

\begin{document}
\section{Section 1}
\subsection{Subsec 1}
\snumreset

\begin{frame}
  \frametitle{\subsecname\snum}
  \begin{itemize}
  \item<1-> bla
  \item<2-> counter should not increase
  \item<3-> counter should again not increase
  \end{itemize}
\end{frame}

\begin{frame}
  \frametitle{\subsecname\snum}
  Counter should be at two. 
\end{frame}
\end{document}

2 Answers 2

1
\documentclass{beamer}

\newcounter{insub}
\AtBeginSubsection[]{\setcounter{insub}{0}}
\AtBeginEnvironment{frame}{\addtocounter{insub}{1}}
\setbeamertemplate{frametitle}{\subsecname{} - \theinsub}

\begin{document}

\subsection{test}
\begin{frame}{.}
    abc
    \pause 
    cdef
\end{frame} 

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

\subsection{test}
\begin{frame}{.}
    abc
    \pause 
    cdef
\end{frame} 

\end{document}
2
  • Thanks, the output PDF looks good but I get two "Undefined control sequence." errors when compiling the tex file.
    – Florian
    Commented Jan 12, 2018 at 23:51
  • @Florian Maybe you have an old beamer version, try with \usepackage{etoolbox}. If this does not help, please add the complete error message. Commented Jan 12, 2018 at 23:53
0

Instead of defining your own counter, you could use the frame number counter, that is not increased with every overlay.

\documentclass{beamer}
\renewcommand{\insertframenumber}{\Roman{framenumber}}

\begin{document}
\section{Section 1}
\subsection{Subsec 1}


\begin{frame}
  \frametitle{\subsecname\insertframenumber}
  \begin{itemize}
  \item<1-> bla
  \item<2-> counter should not increase
  \item<3-> counter should again not increase
  \end{itemize}
\end{frame}

\begin{frame}
  \frametitle{\subsecname\insertframenumber}
  Counter should be at two. 
\end{frame}
\end{document}
1
  • Thanks that works, but I would need to reset the framenumber counter at every new subsection, so I would loose the "real" framenumber counter should I need it somewhere else.
    – Florian
    Commented Jan 12, 2018 at 23:35

You must log in to answer this question.

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