![如何拥有可重述的 tcolorbox 定理环境,同时避免标签被多次定义](https://linux22.com/image/475705/%E5%A6%82%E4%BD%95%E6%8B%A5%E6%9C%89%E5%8F%AF%E9%87%8D%E8%BF%B0%E7%9A%84%20tcolorbox%20%E5%AE%9A%E7%90%86%E7%8E%AF%E5%A2%83%EF%BC%8C%E5%90%8C%E6%97%B6%E9%81%BF%E5%85%8D%E6%A0%87%E7%AD%BE%E8%A2%AB%E5%A4%9A%E6%AC%A1%E5%AE%9A%E4%B9%89.png)
我有一份文档,我想先在其中定义一个定理,然后在需要证明它的时候重新陈述相同的定理。
通常这可以使用thm-restate
包来完成。但是,我的文档中的定理使用 tcolorbox 环境,因此我尝试使用这个答案。
这种方法适用于重述定理,但 LaTeX 会发出有关标签“多重定义”的警告。由于这个错误,我无法正确引用重述定理。
我的问题:我怎样才能重述 tcolorbox 定理,而不遇到标签重复的问题?
以下是展示设置和问题的最小示例:
\documentclass{article}
\usepackage{amsmath}
\usepackage[colorlinks=true, allcolors=blue]{hyperref}
\usepackage{cleveref}
\usepackage{tcolorbox}
\tcbuselibrary{theorems}
\tcbuselibrary{magazine}
\usepackage{amsthm}
\theoremstyle{definition}
% The tcolorbox theorem
\newtcbtheorem{theorem}{Theorem}{colback=gray!10,colframe=gray!40!black}{theorem}
% Commands to restate the theorem
\newcommand{\recallthm}[2][1]{\par\noindent\useboxarray[#2]{#1}}
\usepackage{environ}
\NewEnviron{restatablethm}[2]{%
\newboxarray{#2}%
\begin{theorem}[reset box array=#2, store to box array=#2]{#1}{#2}
\BODY%
\end{theorem}%
\recallthm{#2}%
}
% Other theorem environments might be on the same counter
\newtheorem{lemma}[tcb@cnt@theorem]{Lemma}
\begin{document}
% The first theorem
\begin{restatablethm}{Serious Algorithm}{coollabel}
An example boxed theorem..
\end{restatablethm}
\begin{lemma}
A simple lemma.
\end{lemma}
% The restated theorem
\recallthm{coollabel}
By \Cref{thm:collabel} we are done. % The reference here does not work (yields ??).
\end{document}
答案1
这使用 [nophantom] 创建可调用框,但不创建原始框。它仍会生成有关重复超目标的警告,以及有关发货框的警告。 \Cref
根本不起作用,即使theorem:coollabel@cref
创建了标签。
\documentclass{article}
\usepackage{amsmath}
\usepackage[colorlinks=true, allcolors=blue]{hyperref}
\usepackage{cleveref}
\usepackage{tcolorbox}
\tcbuselibrary{theorems}
\tcbuselibrary{magazine}
\usepackage{amsthm}
\theoremstyle{definition}
% The tcolorbox theorem
\newtcbtheorem{theorem}{Theorem}{colback=gray!10,colframe=gray!40!black}{theorem}
% Commands to restate the theorem
\newcommand{\recallthm}[2][1]{\par\noindent\useboxarray[#2]{#1}}
\usepackage{environ}
\makeatletter
\NewEnviron{restatablethm}[2]{% print this copy
\newboxarray{#2}%
\begin{theorem}[reset box array=#2, store to box array=#2,nophantom]{#1}{#2}
\BODY%
\end{theorem}%
\addtocounter{tcb@cnt@theorem}{-1}%
\begin{theorem}{#1}{#2}
\BODY%
\end{theorem}%
%\recallthm{#2}%
}
% Other theorem environments might be on the same counter
\newtheorem{lemma}[tcb@cnt@theorem]{Lemma}
\begin{document}
% The first theorem
\begin{restatablethm}{Serious Algorithm}{coollabel}
An example boxed theorem..
\end{restatablethm}
\begin{lemma}
A simple lemma.
\end{lemma}
% The restated theorem
\recallthm{coollabel}
By \ref{theorem:coollabel} we are done. % The reference here does not work (yields ??).
\end{document}