15

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
  • 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, 2014 at 20:49

1 Answer 1

21

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

2
  • 1
    Simple as that... I lost one hour today because of this tiny issue! Thank you.
    – remjg
    Sep 15, 2014 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, 2015 at 22:04

You must log in to answer this question.

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