我想使用 Beamer 中的 tcolorbox 让不同的定理环境共享同一个计数器。但是cleveref
似乎无法正确识别它们的名称。有人能指出我做错了什么吗?
以下是 MWE:
\documentclass[10pt,aspectratio=169]{beamer}
\usepackage{amsmath}
\usepackage{amsthm}
\usepackage[most]{tcolorbox}
\tcbuselibrary{theorems}
\usepackage{cleveref}
\crefname{lemma}{lemma}{lemmas}
\crefname{theorem}{theorem}{theorems}
\renewtcolorbox[use counter=theorem]{theorem}[1][]{
title={\thetheorem. Theorem.},
before upper={\tcbtitle\;\itshape},
#1
}
\renewtcolorbox[use counter=theorem]{lemma}[1][]{
title={\thetheorem. Lemma.},
before upper={\tcbtitle\;\itshape},
#1
}
\begin{document}
\begin{frame}{Blah}
\begin{theorem}[label=bar]
Blah blah.
\end{theorem}
\cref{bar}
\begin{lemma}[label=foo]{}{}
Blah blah.
\end{lemma}
\cref{foo}
\end{frame}
\end{document}
我想要“引理 2”而不是“定理 2”。我尝试label type = lemma
按照建议添加这里,但没有任何成功。
答案1
beamer
在交叉引用的处理上相当特殊,但如果您愿意使用zref-clever
,并做一些设置,您可能会遇到以下情况:
\documentclass[10pt,aspectratio=169]{beamer}
\usepackage{amsmath}
\usepackage{amsthm}
\usepackage[most]{tcolorbox}
\tcbuselibrary{theorems}
% Create 'zlabel' and 'zlabel type' options for tcolorbox.
\tcbset{%
zlabel/.style={phantom={\zlabel{#1}}},%
zlabel type/.code={\zcsetup{reftype={#1}}},%
}
\usepackage{zref-clever}
% From "Work-around 2: beamer" in zref-clever's User manual
\makeatletter
\RenewDocumentCommand{\zlabel}{ D<>{1} m }{%
\ifx\label\ltx@gobble
\else
\zref@wrapper@babel{\zref@label<#1>}{#2}%
\fi
}
\NewCommandCopy\beamer@old@zref@label\zref@label
\RenewDocumentCommand{\zref@label}{ D<>{1} m }{%
\alt<#1>{%
\zref@ifpropundefined{anchor}{}{\zref@setcurrent{anchor}{#2}}%
\beamer@old@zref@label{#2}%
\beamer@nameslide{#2}%
}{%
\beamer@dummynameslide%
}%
}
\makeatother
\renewtcolorbox[use counter=theorem]{theorem}[1][]{
title={\thetheorem. Theorem.},
before upper={\tcbtitle\;\itshape},
#1
}
\renewtcolorbox[use counter=theorem]{lemma}[1][]{
title={\thetheorem. Lemma.},
zlabel type={lemma},
before upper={\tcbtitle\;\itshape},
#1
}
\begin{document}
\begin{frame}
\zcref{bar,foo}
\end{frame}
\begin{frame}{Blah}
\begin{theorem}[zlabel=bar]
Blah blah.
\end{theorem}
\zcref{bar}
\begin{lemma}[zlabel=foo]
Blah blah.
\end{lemma}
\zcref{foo}
\end{frame}
\end{document}