我想简单地更新我的序言,使用 tcolorbox 来处理定理,而不需要手动删除\label{}
每个之后的发现\begin{theorem}
或替换与标题相对应的可选参数。也就是说,我希望我的定理环境看起来像
\begin{theorem}[optional title]\label{optional label}
Theorem text.
\end{theorem}
同时仍然使用库tcolorbox
中的定理Theorem
。有办法做到这一点吗?
编辑:这里是 MWE。
\documentclass{article}
\usepackage{amsthm}
\usepackage{tcolorbox}
\tcbuselibrary{theorems}
\newtcbtheorem[
auto counter,
number within=section,
]{theorem}{Theorem}{
colback=gray!25,
colframe=gray!90!black,
fonttitle=\bfseries}{thm}
\begin{document}
\begin{theorem}{tcb label style}{works}
Can cite \ref{thm:works}.
\end{theorem}
\begin{theorem}{default label style}{}
\label{thm:doesntwork}
Can cite \ref{thm:doesntwork}.
\end{theorem}
\end{document}
此外,我的文本编辑器在书写时自动建议标签的任何机制都\ref
无法与\begin{theorem}{title}{label}
tcolorbox 提供的方法兼容。
编辑2:以下内容有效但并不理想。
\newtheoremstyle{tcb-drop-in-thm}% 〈name〉
{}% 〈Space above〉1
{}% 〈Space below 〉1
{}% 〈Body font〉
{}% 〈Indent amount〉2
{\bfseries\color{white}}% 〈Theorem head font〉
{}% 〈Punctuation after theorem head 〉
{\newline}% 〈Space after theorem head 〉3
{\thmname{#1}\thmnumber{ #2}\thmnote{ $\blacktriangleright$ #3}}% 〈Theorem head spec (can be left empty, meaning ‘normal’ )〉
\theoremstyle{tcb-drop-in-thm}
\newtheorem{theorem}{Theorem}[section]
\newtheorem{lemma}[theorem]{Lemma}
\newtheorem{proposition}[theorem]{Proposition}
\usepackage{tcolorbox}
\tcbuselibrary{skins, breakable}
\tcolorboxenvironment{theorem}{%
colback=gray!25,
colframe=gray!90!black,
enhanced,
top=0mm,
overlay={\begin{tcbclipinterior}
\fill[gray!90!black] (frame.north west)rectangle ([yshift=-5mm]frame.north east);
\end{tcbclipinterior}}
}
\begin{document}
\begin{theorem}
\label{thm:test}
test can be referenced as \ref{thm:test}
\end{theorem}
\end{document}