# Stop counter increment in tcolorbox when using overlays in Beamer

I have defined two new theorems, myexample and myexercise, using \newtcbtheorem in the tcolorbox package in Beamer. I have overlays (e.g. \pause, \uncover<2+>{ ... }, etc.) within the new theorems.

1) I would like to be able to 'click' past \pause, \uncover, etc., without incrementing the theorem counter.

2) On slide 1, it seems that the two new theorems have separate counters (as I want them to have) but when I 'click' past \pause to slide 2 in the Example theorem, both the Example and Exercise theorems' counters increment. (Solving my first problem may fix the second?)

I have tried to implement counters but clearly don't have counters figured out since they didn't do what I'd hoped (although they did compile without error). I have commented them out but you can see what I was trying to do.

\documentclass[mathserif]{beamer}
\usepackage[most]{tcolorbox}
\newtcbtheorem{myexample}{Example}{}{exam}
\newtcbtheorem{myexercise}{Exercise}{}{exer}

%\newcounter{examplecounter}

\begin{document}
\begin{frame}{}
\begin{myexample}{}{}
%\setcounter{examplecounter}{\thetcbcounter}
Example 1, part A \theexamplecounter \par
\uncover<2->{
%\setcounter{\tcbcounter}{\theexamplecounter}
Example 1, part B
}
\end{myexample}

\begin{myexample}{}{}
Example 2
\end{myexample}

\begin{myexercise}{}{}
Exercise 1
\end{myexercise}

\end{frame}
\end{document}


Any suggestions would be welcome. Thanks :)

• As far as I know beamer puts each overlay in a TeX box first and decides which box is to be shown. However, the tcolorbox theorem is actually in several boxes then, each incrementing the relevant counter.
– user31729
Sep 17 '16 at 7:42
• You should consider using \resetcounteronoverlays. See the manual for more insights. Sep 17 '16 at 9:01

The macro \tcbcounter contains the name of the current counter, which is context dependent. Note that the myexample and myexercise have different counters.

\documentclass[mathserif]{beamer}
\usepackage[most]{tcolorbox}
\newtcbtheorem{myexample}{Example}{}{exam}
\newtcbtheorem{myexercise}{Exercise}{}{exer}

\resetcounteronoverlays{tcb@cnt@myexample}
\resetcounteronoverlays{tcb@cnt@myexercise}

\begin{document}

\begin{frame}{}
\begin{myexample}{}{}
\tcbcounter\newline
Example 1, part A \thetcbcounter \par
\uncover<2->{
Example 1, part B
}
\end{myexample}

\begin{myexample}{}{}
Example 2
\end{myexample}

\begin{myexercise}{}{}
\tcbcounter\newline
Exercise 1
\end{myexercise}

\end{frame}
\end{document}