Please help me to put a simple counter in the tcolorbox environment in beamer. It only needs to go from 1,2,3,...
\begin{tcolorbox}[colback=green!5,colframe=green!40!black, center,title= ]
\end{tcolorbox}
Please help me to put a simple counter in the tcolorbox environment in beamer. It only needs to go from 1,2,3,...
\begin{tcolorbox}[colback=green!5,colframe=green!40!black, center,title= ]
\end{tcolorbox}
There is the key auto counter for that purpose. As it turns out, it does not yet automatically harmonize with beamer \pauses. This can be fixed by redefining \tcb@proc@counter@auto to become
\def\tcb@proc@counter@auto#1{%
\newcounter{tcb@cnt@#1}%
\csxdef{tcb@cnt@#1}{tcb@cnt@#1}%
\tcb@proc@counter@autoanduse{#1}%
\ifcsname resetcounteronoverlays\endcsname%<-added
\resetcounteronoverlays{tcb@cnt@#1}%<-added
\fi%<-added
}
So the MWE becomes
\documentclass{beamer}
\usepackage{tcolorbox}
\makeatletter
\def\tcb@proc@counter@auto#1{%
\newcounter{tcb@cnt@#1}%
\csxdef{tcb@cnt@#1}{tcb@cnt@#1}%
\tcb@proc@counter@autoanduse{#1}%
\ifcsname resetcounteronoverlays\endcsname%<-added
\resetcounteronoverlays{tcb@cnt@#1}%<-added
\fi%<-added
}
\makeatother
\newtcolorbox[auto counter]{numberedbox}[2][]{%
colback=green!5,colframe=green!40!black,center,title=Numbered
box~\thetcbcounter: #2,#1}
\begin{document}
\begin{frame}[t]
\frametitle{tcolorboxes}
\begin{numberedbox}[label={boxA}]{title A}
I am random box and have number~\ref{boxA}
\end{numberedbox}
\pause
\begin{numberedbox}[label={catinbox}]{A cat in a box}
\dots wrote this, see numbered box~\ref{boxA}
\end{numberedbox}
\pause
\begin{numberedbox}[label={yetanotherbox}]{title B}
I'm boring, see numbered box~\ref{catinbox} for something exciting
\end{numberedbox}
\end{frame}
\end{document}
auto countersupport. Sincetcolorboxgives it some internal name that is not obvious, I added a normal counter here. Maybe that would be something for a feature request to ask to makeauto counterdo that automatically. – Sep 30 '19 at 12:42tcolorbox. It adds the counter to the reset list if the\resetcounteronoverlayscommand is defined, which should be a very good check whether or not that's abeamerdocument. – Oct 01 '19 at 02:58