![重述使用 \newtcbtheorem 创建的定理环境](https://linux22.com/image/455432/%E9%87%8D%E8%BF%B0%E4%BD%BF%E7%94%A8%20%5Cnewtcbtheorem%20%E5%88%9B%E5%BB%BA%E7%9A%84%E5%AE%9A%E7%90%86%E7%8E%AF%E5%A2%83.png)
我看到的第一篇告诉我有关restatable
环境的帖子:回顾一个定理。关于这样的事情,人们提出了几个问题:建立可重述的盒子定理说使用\declaretheoremstyle
;在自定义环境中使用 restatable使用起来没问题\newenvironment
,但会弄乱计数器。两者似乎都与我的定理颜色盒不太兼容:
\newtcbtheorem[number within=section]{mylemma}{Lemma}%
{colframe=blue!45!white,enlarge top by=0.15cm,before
skip=3pt,after skip=6.5pt,fonttitle=\slshape,breakable}{lem}
通常我可以通过以下方式使用这个环境
\begin{mylemma}{Lemma Name}{lemmalabel}
...
\end{mylemma}
(最后一个参数是标签)。以下是回顾一个定理我天真地写了以下代码:
\documentclass{article}
\usepackage{amsmath}
\usepackage{tcolorbox}
\tcbuselibrary{theorems}
\tcbuselibrary{breakable}
\usepackage[colorlinks = true, urlcolor = red]{hyperref}
\newtcbtheorem[number within=section]{mylemma}{Lemma}%
{colframe=blue!45!white,enlarge top by=0.15cm,before
skip=3pt,after skip=6.5pt,fonttitle=\slshape,breakable}{lem}
\usepackage{thmtools}
\declaretheorem[name=Theorem,numberwithin=section]{thm}
\begin{document}
\begin{mylemma}{Substitution lemma}{substitution}
Lemma in a tcolorbox
\end{mylemma}
\begin{restatable}{thm}{thmlabel}
Restatable theorem with thmtools
\end{restatable}
Theorem restated: \thmlabel*
\begin{restatable}{mylemma}{lemmalabel}
Restatable lemma in a tcolorbox
\end{restatable}
Lemma restated: \lemmalabel*
Reference to the lemma \ref{lem:substitution}
\end{document}
但这不起作用(如果删除尝试,它确实有效\begin{restatable}{mylemma}...
)。是否可以调整restatable
(和restatable*
)环境以允许以下用法:
\begin{restatable}{mylemma}{Lemma Name}{lemmalabel}
...
\end{restatable}
\lemmalabel*
Lemma \ref{lem:lemmalabel}
生产两份相同的mylemma
?
附注(由 CarLaTeX 解决,方法是thmtools
将\newtcbtheorem
) 当我在玩这个包时,thmtools
我注意到我的定义的一些引用指向了错误的页面(例如它会显示 Def. 2.8 然后链接到 Def. 1.8)。我提供了一个 MWE:
\documentclass{article}
\usepackage{amsmath}
\usepackage{tcolorbox}
\tcbuselibrary{theorems}
\tcbuselibrary{breakable}
\usepackage[colorlinks = true, urlcolor = red]{hyperref}
\usepackage{thmtools}
\newtcbtheorem[number within=section]{mydef}{Definition}%
{colframe=red!65!black,enlarge top by=0.15cm,before
skip=3pt,after skip=6.5pt,fonttitle=\slshape,breakable}{def}
\begin{document}
\section*{220A Class Notes}
\section{Lecture 1}
\subsection{9/26/22 Class 2}
\begin{mydef}{Height of term}{term-height}
\end{mydef}
\begin{mydef}{Atomic formulas}{atomic-formula}
\end{mydef}
\begin{mydef}{Formulas}{formula}
\end{mydef}
\newpage
\section{Lecture 2}
\subsection{9/28/22 Class 3}
\begin{mydef}{Tarski's definition of truth/formula satisfaction}{tarski-truth}
\end{mydef}
\subsection{9/30/22 Class 4}
\begin{mydef}{Formulas as functions, notation}{formula-function-notation}
...
\end{mydef}
\newpage
\section{Lecture 3}
Definition \ref{def:formula-function-notation}
\end{document}
这似乎是一个已知问题:如果使用 thmtools,pageref 会出现错误页面但是答案描述的修复(放在\label
某个位置)不适用于,\newtcbtheorem
因为标签是隐式放置的,tcbtheorem
而不是由用户明确放置的。
答案1
尝试一下这个:
\documentclass{article}
\usepackage{amsmath}
\usepackage{tcolorbox}
\tcbuselibrary{theorems}
\tcbuselibrary{magazine}% also load breakable
%\tcbuselibrary{breakable}
\usepackage[colorlinks = true, urlcolor = red]{hyperref}
\newtcbtheorem[number within=section]{mylemma}{Lemma}%
{colframe=blue!45!white,enlarge top by=0.15cm,before
skip=3pt,after skip=6.5pt,fonttitle=\slshape,breakable}{lem}
\newcommand{\myrecall}[2][1]{\par\noindent\useboxarray[#2]{#1}}
\usepackage{environ}
\NewEnviron{restatlemma}[2]{%
\newboxarray{#2}%
\begin{mylemma}[reset box array=#2, store to box array=#2]{#1}{#2}
\BODY%
\end{mylemma}%
\myrecall{#2}%
}
\usepackage{thmtools}
\declaretheorem[name=Theorem,numberwithin=section]{thm}
\begin{document}
\begin{mylemma}{Substitution lemma}{substitution}
Lemma in a tcolorbox
\end{mylemma}
\begin{restatable}{thm}{thmlabel}
Restatable theorem with thmtools
\end{restatable}
Theorem restated: \thmlabel*
\begin{restatlemma}{My Title}{lemmalabel}
Lemma stored in a tcolorbox
\end{restatlemma}
Lemma restated: \myrecall{lemmalabel}
Reference to the lemma \ref{lem:substitution}
\end{document}