如何重置计数器以达到最新定理/定义/其他?

如何重置计数器以达到最新定理/定义/其他?

我喜欢给出常见的例子,并希望根据刚刚展示的任何定义/定理/引理/推论/任何内容对这些例子进行编号。如果可能的话,我还希望这个编号是按字母顺序排列的。

例如,我希望下面示例中的编号分别为 1.1.1a、1.1.1a、1.1.2a 和 1.1.2b。

电流输出:

在此处输入图片描述

当前 TeX:

\documentclass[12pt, letterpaper]{article}
\usepackage{amsmath}
\usepackage{amsthm}
\usepackage{chngcntr}
\renewcommand{\qedsymbol}{\rule{0.7em}{0.7em}}
\newcommand{\Mod}[1]{\ (\mathrm{mod}\ #1)}
\counterwithin{figure}{section}
\theoremstyle{definition}
\newtheorem{exmp}{Example}[subsection]
\newtheorem{theorem}{Theorem}[subsection]
\newtheorem{corollary}{Corollary}[theorem]
\newtheorem{definition}{Definition}[subsection]
\newtheorem{lemma}[section]{Lemma}
\numberwithin{equation}{section}

\begin{document}
\section{How To Add}
\subsection{A Detailed Look}

\begin{definition}
    \textbf{addition} is denoted with the + symbol
\end{definition}
\begin{exmp}
    1+0=1
\end{exmp}
\begin{theorem}
    \textbf{Trichotomy I:} The addition of two positives is positive.
\end{theorem}
\begin{exmp}
    Not sufficient since (-1)+2=1
\end{exmp}  
\begin{theorem}
    \textbf{Trichotomy II:} The addition of two negatives is negative.
\end{theorem}
\begin{exmp}
    (-1)+(-2)=-3
\end{exmp}
\begin{exmp}
    Not sufficient since (-2)+1=-1
\end{exmp}
\end{document}

有任何想法吗?

答案1

您可以定义一个示例计数器“前缀”,并且该前缀会随着您可能考虑在其后有示例的每个环境的使用而更新。

在此处输入图片描述

\documentclass{article}

\usepackage{amsthm}
\usepackage{chngcntr}
\usepackage{etoolbox}

\theoremstyle{definition}
\newtheorem{theorem}{Theorem}[subsection]
\newtheorem{definition}{Definition}[subsection]
\newtheorem{exmp}{Example}

% Capture latest environment that could have an example following it
\AtEndEnvironment{theorem}{\global\let\exampleprefix\thetheorem}
\AtEndEnvironment{definition}{\global\let\exampleprefix\thedefinition}

% Adjust Example counter to be reset with every theorem, definition, ...
\counterwithin{exmp}{theorem}
\counterwithin{exmp}{definition}
% Update representation of Example counter
\newcommand{\exampleprefix}{}% Define Example counter prefix to be empty at first
\renewcommand{\theexmp}{\exampleprefix\alph{exmp}}% Prefix counter with whatever environment was used previously

\begin{document}

\section{How To Add}
\subsection{A Detailed Look}

\begin{definition}
\textbf{addition} is denoted with the + symbol
\end{definition}

\begin{exmp}
$1 + 0 = 1$
\end{exmp}

\begin{theorem}
\textbf{Trichotomy I:} The addition of two positives is positive.
\end{theorem}

\begin{exmp}
Not sufficient since $(-1) + 2 = 1$
\end{exmp}

\begin{theorem}
\textbf{Trichotomy II:} The addition of two negatives is negative.
\end{theorem}

\begin{exmp}
$(-1) + (-2) = -3$
\end{exmp}

\begin{exmp}
Not sufficient since $(-2) + 1 = -1$
\end{exmp}

\end{document}

答案2

请不要对定理、定义、引理和推论使用独立编号。当您通过编号交叉引用它们时,您的读者将无法找到它们。

在这种情况下,示例编号为 1.1.1a,因此编号毫无用处。

如果您接受这个建议,那么您只需定义exmp将其计数器与绑定即可definition

\documentclass{article}
\usepackage{amsthm}

\theoremstyle{definition}

\newtheorem{definition}{Definition}[subsection]
\newtheorem{theorem}[definition]{Theorem}
\newtheorem{corollary}[definition]{Corollary}
\newtheorem{lemma}[definition]{Lemma}
\newtheorem{exmp}{Example}
\counterwithin*{exmp}{definition}
\renewcommand{\theexmp}{\thedefinition\alph{exmp}}

\begin{document}

\section{How To Add}

\subsection{A Detailed Look}

\begin{definition}
    \textbf{addition} is denoted with the + symbol
\end{definition}
\begin{exmp}
    1+0=1
\end{exmp}
\begin{theorem}
    \textbf{Trichotomy I:} The addition of two positives is positive.
\end{theorem}
\begin{exmp}
    Not sufficient since (-1)+2=1
\end{exmp}  
\begin{theorem}
    \textbf{Trichotomy II:} The addition of two negatives is negative.
\end{theorem}
\begin{exmp}
    (-1)+(-2)=-3
\end{exmp}
\begin{exmp}
    Not sufficient since (-2)+1=-1
\end{exmp}

\subsection{A Check}

\begin{definition}
    \textbf{addition} is denoted with the + symbol
\end{definition}
\begin{exmp}
    1+0=1
\end{exmp}
\begin{theorem}
    \textbf{Trichotomy I:} The addition of two positives is positive.
\end{theorem}
\begin{exmp}
    Not sufficient since (-1)+2=1
\end{exmp}  
\begin{theorem}
    \textbf{Trichotomy II:} The addition of two negatives is negative.
\end{theorem}
\begin{exmp}
    (-1)+(-2)=-3
\end{exmp}
\begin{exmp}
    Not sufficient since (-2)+1=-1
\end{exmp}

\end{document}

在此处输入图片描述

否则,对 Werner 的代码稍作修改:

\documentclass{article}
\usepackage{amsthm}

\theoremstyle{definition}

\newtheorem{definition}{Definition}[subsection]
\newtheorem{theorem}{Theorem}[subsection]
\newtheorem{corollary}{Corollary}[theorem]
\newtheorem{lemma}{Lemma}[section]
\newtheorem{exmp}{Example}
\counterwithin*{exmp}{definition}
\counterwithin*{exmp}{theorem}
\counterwithin*{exmp}{lemma}
\counterwithin*{exmp}{corollary}
\renewcommand{\theexmp}{\thelaststatement\alph{exmp}}

\AtEndEnvironment{definition}{\xdef\thelaststatement{\thedefinition}}
\AtEndEnvironment{theorem}{\xdef\thelaststatement{\thetheorem}}
\AtEndEnvironment{corollary}{\xdef\thelaststatement{\thecorollary}}
\AtEndEnvironment{lemma}{\xdef\thelaststatement{\thelemma}}

\begin{document}

\section{How To Add}

\subsection{A Detailed Look}

\begin{definition}
    \textbf{addition} is denoted with the + symbol
\end{definition}
\begin{exmp}
    1+0=1
\end{exmp}
\begin{theorem}
    \textbf{Trichotomy I:} The addition of two positives is positive.
\end{theorem}
\begin{exmp}
    Not sufficient since (-1)+2=1
\end{exmp}  
\begin{theorem}
    \textbf{Trichotomy II:} The addition of two negatives is negative.
\end{theorem}
\begin{exmp}
    (-1)+(-2)=-3
\end{exmp}
\begin{exmp}
    Not sufficient since (-2)+1=-1
\end{exmp}

\subsection{A Check}

\begin{definition}
    \textbf{addition} is denoted with the + symbol
\end{definition}
\begin{exmp}
    1+0=1
\end{exmp}
\begin{theorem}
    \textbf{Trichotomy I:} The addition of two positives is positive.
\end{theorem}
\begin{exmp}
    Not sufficient since (-1)+2=1
\end{exmp}  
\begin{theorem}
    \textbf{Trichotomy II:} The addition of two negatives is negative.
\end{theorem}
\begin{exmp}
    (-1)+(-2)=-3
\end{exmp}
\begin{exmp}
    Not sufficient since (-2)+1=-1
\end{exmp}

\end{document}

在此处输入图片描述

相关内容