在如何保持相同的数字重述定理?,Thomas F. Sturm
给出了完美的答案,但现在我发现我希望它是“过去完成时”,因为我还希望能够而refer to the restated theorem
不仅仅是原始陈述。
但是当我插入时,[label={thm:1-1a}]
它\begin{duplicate}{thm:1-1}{~}
会编译为重述定理所在的小节的引用或??,具体取决于我插入的位置。当然,这意味着我应该修改的定义,\newtcolorbox{duplicate}
但我不知道该怎么做。
答案1
最简单的方法似乎是
\newtcolorbox[auto counter,number within=chapter]%
{duplicate}%
[3][]%
{% Rest of options
}
其中duplicate
是单独计算的定理。这将使用\refstepcounter
宏,否则将获取在组外定义的label=
最后一个内容,在本例中来自。\@currentlabel
\subsection
\documentclass{book}
\usepackage{makeidx}
\usepackage[hyperfootnotes=false]{hyperref}%[pdfborder={0 0 0}]
%Begin the ``quick and dirty hack'' due to Heiko Oberdiek which loads showidx
\makeatletter
\ifHy@hyperindex
\def\HyInd@ParenLeft{(}%
% Hook in \HyInd@@wrindex
\let\HyInd@showidx\@empty
% Hook in \HyInd@@wrindex for package showidx
\def\HyInd@showidx#1{%
\@showidx{#1}%
\if@nobreak
\ifvmode
\nobrak
\fi
\fi
}%
% Load package showidx
\let\siOrg@makeindex\makeindex
\let\siOrg@@index\@index
\let\siOrg@@wrindex\@wrindex
\let\siOrg@index\index
\RequirePackage{showidx}
\let\makeindex\siOrg@makeindex
\let\@index\siOrg@@index
\let\@wrindex\siOrg@@wrindex
\let\index\siOrg@index
% rest of hyperref part
\@ifpackageloaded{multind}{%
\let\HyInd@org@wrindex\@wrindex
\def\@wrindex#1#2{\HyInd@@wrindex{#1}#2||\\}%
\def\HyInd@@wrindex#1#2|#3|#4\\{%
\ifx\\#3\\%
\HyInd@org@wrindex{#1}{#2|hyperpage}%
\else
\def\Hy@temp@A{#3}%
\ifx\Hy@temp@A\HyInd@ParenLeft
HyInd@org@wrindex{#1}{#2|#3hyperpage}%
\else
\HyInd@org@wrindex{#1}{#2|#3}%
\fi
\fi
}%
}{%
\def\@wrindex#1{\@@wrindex#1||\\}
\def\@@wrindex#1|#2|#3\\{%
\ifx\\#2\\%
\protected@write\@indexfile{}{%
\string\indexentry{#1|hyperpage}{\thepage}%
}%
\else
\def\Hy@temp@A{#2}%
\ifx\Hy@temp@A\HyInd@ParenLeft
\protected@write\@indexfile{}{%
\string\indexentry{#1|#2hyperpage}{\thepage}%
}%
\else
\protected@write\@indexfile{}{%
\string\indexentry{#1|#2}{\thepage}%
}%
\fi
\fi
\endgroup
\HyInd@showidx{#1}%
\@esphack
}%
}%
\fi
\makeatother
%End the ``quick and dirty hack'' due to Heiko Oberdiek which loads showidx
\hypersetup{
colorlinks,
linkcolor={red!50!black},
citecolor={blue!50!black},
urlcolor={blue!80!black}
}%end colors
\usepackage{tcolorbox}
\tcbuselibrary{skins}
\newcounter{thm}%[chapter]
\usepackage{cleveref}
\newtcolorbox%
[%
use counter= thm,
number within=chapter,
number freestyle={\noexpand\thechapter.\noexpand\arabic{\tcbcounter}~\noexpand\mytitle},%
list inside= thm,%creates the list under tcblistof
list type=heorem,
crefname={Theorem}{Theorems},
Crefname={Theorem}{Theorems},
]%
{heorem}%
[2][]%
{%
detach title,%
before upper={\tcbtitle\quad},%
%breakable,%
enhanced,%
arc=0.2mm,%
%fontupper=\sffamily,
colback=green!5,%
colframe=green!35!black,%
fonttitle=\bfseries,%
coltitle=black,%
code={\gdef\mytitle{#2}},
%code={\def\mytitle{#2}},%
title=THEOREM \thetcbcounter,%
list entry={Theorem~\thetcbcounter},
#1%
}%
%Begin the Sharpe (2013-01-18) code as modified by Schulz (2016-02-1) to have math in Showindex
\let\oldopenparen\(
\let\oldcloseparen\)
\def\({\protect\oldopenparen}
\def\){\protect\oldcloseparen}
\newcommand{\INDEX}[1]{\index{#1}}
%End the Sharpe (2013-01-18) code as modified by Schulz (2016-02-1) to have math in Showindex
\newcommand*{\fullref}[1]{\hyperref[{#1}]{\cref*{#1} \nameref*{#1} \pageref*{#1}}}
%\theoremstyle{empty}%Does not work here.
\newtcolorbox[auto counter,number within=chapter]%
{duplicate}%
[3][]%
{%
detach title,%
before upper={\tcbtitle\quad},%
enhanced,%
arc=0.2mm,%
colback=green!5,%
colframe=green!35!black,%
fonttitle=\bfseries,%
coltitle=black,%
code={\gdef\mytitle{#3}},
title=THEOREM~\ref{#2},%
%list entry={Theorem~\thetcbcounter},
#1%
}%
\begin{document}
\chapter{Foo chapter}
\section{Foo section}
\subsection{Foo subsection}
\begin{heorem}[label={thm:1-1}]{~}\hspace{-4mm}
\emph{Signed addition} and \emph{signed subtraction} of the same amount undo each other.
\end{heorem}
\clearpage
\begin{duplicate}[label={thm:1-1a}]{thm:1-1}{~}
Translations of opposite amounts undo each other.
\end{duplicate}
Now see \ref{thm:1-1a}.
\end{document}
按照我在此处的回答进行更正:如何仅显示对 tcolorbox 的 cleveref 引用的标题?
关于\cref
和\nameref
问题...
\documentclass{book}
\usepackage{makeidx}
\usepackage[hyperfootnotes=false]{hyperref}%[pdfborder={0 0 0}]
%Begin the ``quick and dirty hack'' due to Heiko Oberdiek which loads showidx
\makeatletter
\ifHy@hyperindex
\def\HyInd@ParenLeft{(}%
% Hook in \HyInd@@wrindex
\let\HyInd@showidx\@empty
% Hook in \HyInd@@wrindex for package showidx
\def\HyInd@showidx#1{%
\@showidx{#1}%
\if@nobreak
\ifvmode
\nobrak
\fi
\fi
}%
% Load package showidx
\let\siOrg@makeindex\makeindex
\let\siOrg@@index\@index
\let\siOrg@@wrindex\@wrindex
\let\siOrg@index\index
\RequirePackage{showidx}
\let\makeindex\siOrg@makeindex
\let\@index\siOrg@@index
\let\@wrindex\siOrg@@wrindex
\let\index\siOrg@index
% rest of hyperref part
\@ifpackageloaded{multind}{%
\let\HyInd@org@wrindex\@wrindex
\def\@wrindex#1#2{\HyInd@@wrindex{#1}#2||\\}%
\def\HyInd@@wrindex#1#2|#3|#4\\{%
\ifx\\#3\\%
\HyInd@org@wrindex{#1}{#2|hyperpage}%
\else
\def\Hy@temp@A{#3}%
\ifx\Hy@temp@A\HyInd@ParenLeft
HyInd@org@wrindex{#1}{#2|#3hyperpage}%
\else
\HyInd@org@wrindex{#1}{#2|#3}%
\fi
\fi
}%
}{%
\def\@wrindex#1{\@@wrindex#1||\\}
\def\@@wrindex#1|#2|#3\\{%
\ifx\\#2\\%
\protected@write\@indexfile{}{%
\string\indexentry{#1|hyperpage}{\thepage}%
}%
\else
\def\Hy@temp@A{#2}%
\ifx\Hy@temp@A\HyInd@ParenLeft
\protected@write\@indexfile{}{%
\string\indexentry{#1|#2hyperpage}{\thepage}%
}%
\else
\protected@write\@indexfile{}{%
\string\indexentry{#1|#2}{\thepage}%
}%
\fi
\fi
\endgroup
\HyInd@showidx{#1}%
\@esphack
}%
}%
\fi
\makeatother
%End the ``quick and dirty hack'' due to Heiko Oberdiek which loads showidx
\hypersetup{
colorlinks,
linkcolor={red!50!black},
citecolor={blue!50!black},
urlcolor={blue!80!black}
}%end colors
\usepackage{tcolorbox}
\tcbuselibrary{skins}
\newcounter{thm}%[chapter]
\usepackage{cleveref}
%
\newtcolorbox%
[%
use counter= thm,
number within=chapter,
number freestyle={\noexpand\thechapter.\noexpand\arabic{\tcbcounter}~\noexpand\mytitle},%
list inside= thm,%creates the list under tcblistof
list type=heorem,
crefname={Theorem}{Theorems},
Crefname={Theorem}{Theorems},
]%
{heorem}%
[2][]%
{%
detach title,%
before upper={\tcbtitle\quad},%
%breakable,%
enhanced,%
arc=0.2mm,%
%fontupper=\sffamily,
colback=green!5,%
colframe=green!35!black,%
fonttitle=\bfseries,%
coltitle=black,%
code={\gdef\mytitle{#2}},
%code={\def\mytitle{#2}},%
title=THEOREM \thetcbcounter,%
list entry={Theorem~\thetcbcounter},
#1%
}%
%Begin the Sharpe (2013-01-18) code as modified by Schulz (2016-02-1) to have math in Showindex
\let\oldopenparen\(
\let\oldcloseparen\)
\def\({\protect\oldopenparen}
\def\){\protect\oldcloseparen}
\newcommand{\INDEX}[1]{\index{#1}}
%End the Sharpe (2013-01-18) code as modified by Schulz (2016-02-1) to have math in Showindex
\newcommand*{\fullref}[1]{\hyperref[{#1}]{\cref*{#1} \nameref*{#1} \pageref*{#1}}}
%\theoremstyle{empty}%Does not work here.
\makeatletter
\newtcolorbox[auto counter,number within=chapter,
crefname={Restated}{Restated},
]%
{duplicate}%
[3][]%
{%
detach title,%
before upper={\tcbtitle\quad},%
enhanced,%
arc=0.2mm,%
colback=green!5,%
colframe=green!35!black,%
fonttitle=\bfseries,%
coltitle=black,%
code={\gdef\mytitle{#3}\edef\@currentlabelname{THEOREM~\getrefnumber{#2}}},
title=THEOREM~\ref{#2},%
%nameref={THEOREM~\getrefnumber{#2}},
#1%
}%
\makeatother
\begin{document}
\chapter{Foo chapter}
\section{Foo section}
\subsection{Foo subsection}
\begin{heorem}[label={thm:1-1}]{~}\hspace{-4mm}
\emph{Signed addition} and \emph{signed subtraction} of the same amount undo each other.
\end{heorem}
\clearpage
\begin{duplicate}[label={thm:1-1a}]{thm:1-1}{~}
Translations of opposite amounts undo each other.
\end{duplicate}
Now see \cref{thm:1-1a} or \nameref*{thm:1-1a}.
\end{document}