我怎样才能使枚举计数器跟随另一个计数器?

我怎样才能使枚举计数器跟随另一个计数器?

例如,在下面的 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为的值,并在结束时将其设置为的值。theoremtheoremenumi

\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}

输出:

上述代码的输出

相关内容