![如何擁有可恢復的 tcolorbox 定理環境,同時避免標籤被多重定義](https://rvso.com/image/475705/%E5%A6%82%E4%BD%95%E6%93%81%E6%9C%89%E5%8F%AF%E6%81%A2%E5%BE%A9%E7%9A%84%20tcolorbox%20%E5%AE%9A%E7%90%86%E7%92%B0%E5%A2%83%EF%BC%8C%E5%90%8C%E6%99%82%E9%81%BF%E5%85%8D%E6%A8%99%E7%B1%A4%E8%A2%AB%E5%A4%9A%E9%87%8D%E5%AE%9A%E7%BE%A9.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}