11

It seems that a frame with overlays in Beamer needs to be processed multiple times. The problem is that a counter that should only be incremented once is incremented more than expected.

How to avoid counters to be incremented multiple times in a Beamer presentation with overlays ?

Minimal working example

\documentclass{beamer}
\newcounter{Test}

\begin{document}
\begin{frame}
  \begin{itemize}
    \item Should be 0: \theTest
    \stepcounter{Test}\pause
    \item Should be 1: \theTest
    \stepcounter{Test}\pause
    \item Should be 2: \theTest
    \stepcounter{Test}\pause   
  \end{itemize}
\end{frame}
\end{document}

Output

Output

  • 1
    beamer treats every slide as a separate chunk of code and executes them as many times as the number of slides. So it reads the counter incrementing lines more than you issue them. – percusse Sep 15 '14 at 20:49
17

Add \resetcounteronoverlays{Test} to your preamble

\documentclass{beamer}
\newcounter{Test}
\resetcounteronoverlays{Test}

\begin{document}
\begin{frame}
  \begin{itemize}
    \item Should be 0: \theTest
    \stepcounter{Test}\pause
    \item Should be 1: \theTest
    \stepcounter{Test}\pause
    \item Should be 2: \theTest
    \stepcounter{Test}\pause
  \end{itemize}
\end{frame}
\end{document}

enter image description here

See section 9.6 of the manual

  • 1
    Simple as that... I lost one hour today because of this tiny issue! Thank you. – remjg Sep 15 '14 at 21:05
  • 1
    thank you very much, I tried to obtained this long, not obvious to find it in a doc. – lehalle Feb 11 '15 at 22:04

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.