LaTeX
对于、等中的普通定理环境amslatex
,您可以轻松设置定理编号,例如通过临时设置适当的计数器,或者通过重新定义创建标签的函数等。
tcolorbox
创建的定理环境是否\newtcbtheorem
具有重置定理数字的功能。
这是一个最小的例子。我需要做什么才能使本文档中的定理成为“定理 7.9”?
\documentclass{article}
\usepackage{tcolorbox}
\tcbuselibrary{theorems}
\newtcbtheorem{Theorem}{Theorem}{}{Th}
\begin{document}
\begin{Theorem}{}{}
We have $2 + 2 = 4$.
\end{Theorem}
\end{document}
答案1
据我所知,除了使用密钥之外,该tcolorbox
包没有其他简单的方法来操作计数器值code=
code={\setcounter{\tcbcounter}{8}}
其中,\tcbcounter
用所用盒子的实际计数器名称替换。
可以number within=section
实现定理计数器在节内的自动复位。
\documentclass{article}
\usepackage{tcolorbox}
\tcbuselibrary{theorems}
\newtcbtheorem[number within=section]{Theorem}{Theorem}{}{Th}
\begin{document}
\setcounter{section}{6}
\section{My nice section}
\begin{Theorem}[code={\setcounter{\tcbcounter}{8}}]{}{}
We have $2 + 2 = 4$.
\end{Theorem}
\end{document}
更新
\documentclass{article}
\usepackage{tcolorbox}
\tcbuselibrary{theorems}
\newtcbtheorem[number within=section]{Theorem}{Theorem}{}{Th}
\makeatletter
\newcommand{\providetcbcountername}[1]{%
\@ifundefined{c@tcb@cnt@#1}{%
--undefined--%
}{%
tcb@cnt@#1%
}
}
\newcommand{\settcbcounter}[2]{%
\@ifundefined{c@tcb@cnt@#1}{%
\GenericError{Error}{counter name #1 is no tcb counter }{}{}%
}{%
\setcounter{tcb@cnt@#1}{#2}%
}%
}%
\newcommand{\displaytcbcounter}[1]{% Wrapper for \the...
\@ifundefined{thetcb@cnt@#1}{%
\GenericError{Error}{counter name #1 is no tcb counter }{}{}%
}{%
\csname thetcb@cnt@#1\endcsname%
}%
}
\begin{document}
\setcounter{section}{6}
\section{My nice section}
\settcbcounter{Theorem}{8}
The counter for theorem is \providetcbcountername{Theorem} and it has the value of \displaytcbcounter{Theorem}
\begin{Theorem}{}{}
We have $2 + 2 = 4$.
\end{Theorem}
\end{document}
答案2
您可以使用 *-variant:
\documentclass{article}
\usepackage{tcolorbox}
\tcbuselibrary{theorems}
\providecommand\theoremnumber{}
\newtcbtheorem{Theorembase}{Theorem \theoremnumber}{}{Th}
\newenvironment{Theorem}[1]
{\renewcommand{\theoremnumber}{#1}\begin{Theorembase*}}
{\end{Theorembase*}}
\begin{document}
\begin{Theorem}{7.9}{}
We have $2 + 2 = 4$.
\end{Theorem}
\end{document}
的第二个参数\begin{theorem}
是可选标题,就像普通tcb
定理一样。