tcolorbox
请帮我在环境中放置一个简单的计数器beamer
。它只需要从 1、2、3 开始......
\begin{tcolorbox}[colback=green!5,colframe=green!40!black, center,title= ]
\end{tcolorbox}
答案1
这就是实现这一目的的关键auto counter
。事实证明,它尚未自动与beamer
\pause
s 协调一致。可以通过重新定义\tcb@proc@counter@auto
为以下形式来解决这个问题:
\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
}
因此 MWE 变成
\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}