每节后归零定理数

每节后归零定理数

我想打电话

\setcounter{theorem}{0}

每次之后\section无论是否\section{something}\section*{something}调用。

我怎样才能做到这一点?

答案1

\section这是一个开始,使用覆盖xparse

在此处输入图片描述

\documentclass{article}

\usepackage{amsthm,xparse}
\newtheorem{theorem}{Theorem}

\let\oldsection\section
\RenewDocumentCommand{\section}{s o m}{%
  \setcounter{theorem}{0}% Reset theorem counter
  \IfBooleanTF{#1}%
    {\oldsection*{#3}}% \section*[.]{..}
    {\IfNoValueTF{#2}
       {\oldsection{#3}}% \section{..}
       {\oldsection[#2]{#3}}% \section[.]{..}
    }%
}

\begin{document}

\section{A section}
\begin{theorem}[Something]
Some theorem.
\end{theorem}

\begin{theorem}[Something]
Some theorem.
\end{theorem}

\section*{Another section}
\begin{theorem}[Something]
Some theorem.
\end{theorem}

\begin{theorem}[Something]
Some theorem.
\end{theorem}

\section{A section}
\begin{theorem}[Something]
Some theorem.
\end{theorem}

\begin{theorem}[Something]
Some theorem.
\end{theorem}

\end{document}

答案2

这会在代码中添加重置 — — 但是,我已将定理编号中\section删除。\thesection

如果这个要求不成立的话,事情就会变得更容易\section*

\documentclass{article}

\usepackage{amsthm}
\usepackage{xpatch}
\newtheorem{theorem}{My Theorem}
%\renewcommand{\thetheorem}{\arabic{theorem}} % it's the default

\xpretocmd{\section}{\setcounter{theorem}{0}}{}{}

\begin{document}

\section{First}
\begin{theorem}[Theorem of everything]
A theorem
\end{theorem}

\section*{First unnumbered section}
\begin{theorem}[A new theorem]
Another theorem
\end{theorem}

\section{Second}
\begin{theorem}[Another important theorem]
Yet another important stuff in her
\end{theorem}


\end{document}

相关内容