例如,在下面的 MWE 中,我如何使用定理计数器标记项目?
\documentclass{article}
\usepackage{amsthm,thmtools,lipsum}
\declaretheorem[name=Theorem, numberwithin=section]{theorem}
\begin{document}
\section{First section}
\begin{theorem}
This is a theorem.
\end{theorem}
\lipsum[1]
\begin{enumerate}
\item The label of this item should be 1.2.
\item The label of this item should be 1.3.
\end{enumerate}
\end{document}
答案1
您必须在开始时将计数器设置enumi
为的值,并在结束时将其设置为的值。theorem
theorem
enumi
\documentclass{article}
\usepackage{amsthm,thmtools,enumitem,lipsum}
\declaretheorem[name=Theorem, numberwithin=section]{theorem}
\newenvironment{thmenumerate}
{\enumerate[
label=\thesection.\arabic*,
before=\setcounter{enumi}{\value{theorem}},
after=\setcounter{theorem}{\value{enumi}},
]}
{\endenumerate}
\begin{document}
\section{First section}
\begin{theorem}
This is a theorem.
\end{theorem}
\lipsum[1]
\begin{thmenumerate}
\item The label of this item should be 1.2.
\item The label of this item should be 1.3.
\end{thmenumerate}
\begin{theorem}
This is a theorem.
\end{theorem}
\lipsum[1]
\begin{thmenumerate}
\item The label of this item should be 1.5.
\item The label of this item should be 1.6.
\end{thmenumerate}
\end{document}
您可能想要更改标签的格式以便与定理的格式一致。
\documentclass{article}
\usepackage{amsthm,thmtools,enumitem,lipsum}
\declaretheorem[name=Theorem, numberwithin=section]{theorem}
\newenvironment{thmenumerate}
{\enumerate[
leftmargin=*,
label=\bfseries\thesection.\arabic*.,
ref=\thesection.\arabic*,
before=\setcounter{enumi}{\value{theorem}},
after=\setcounter{theorem}{\value{enumi}},
]}
{\endenumerate}
\begin{document}
\section{First section}
\begin{theorem}
This is a theorem.
\end{theorem}
\lipsum[1]
\begin{thmenumerate}
\item The label of this item should be 1.2.
\item The label of this item should be 1.3.
\end{thmenumerate}
\begin{theorem}
This is a theorem.
\end{theorem}
\lipsum[1]
\begin{thmenumerate}
\item The label of this item should be 1.5.
\item The label of this item should be 1.6.
\end{thmenumerate}
\end{document}
答案2
好吧,毕竟我想我可以给这个代码一个机会:
\documentclass{article}
\usepackage{amsthm,thmtools,enumitem,lipsum}
\declaretheorem[name=Theorem, numberwithin=section]{theorem}
\makeatletter
\newenvironment{thmenumerate}
{\enumerate[
label=\thetheorem,
before=\def\@listctr{theorem}
]}
{\endenumerate}
\makeatother
\begin{document}
\section{First section}
\begin{theorem}
This is a theorem.
\end{theorem}
\lipsum[1]
\begin{thmenumerate}
\item The label of this item should be 1.2.
\item The label of this item should be 1.3.
\end{thmenumerate}
\begin{theorem}
This is a theorem.
\end{theorem}
\lipsum[1]
\begin{thmenumerate}
\item The label of this item should be 1.5.
\item The label of this item should be 1.6.
\end{thmenumerate}
\end{document}
输出: