我为大多数文档设置了编号系统,使用方法如下:
\newtheorem{theorem}{Theorem}[section]
\newtheorem{lemma}[theorem]{Lemma}
\newtheorem{corollary}[theorem]{Corollary}
显而易见的是:
Theorem 1.1
Lemma 1.2
Theorem 1.3
Corollary 1.4
etc.
但是我试图在文档中途重新定义上述所有内容,以查看小节而不仅仅是节:
Theorem 2.1.1
Corollary 2.1.2
Theorem 2.1.3
Lemma 2.1.4
Theorem 2.2.1
etc.
我似乎找不到办法做到这一点。可能吗?我尝试使用 ntheorem 包,但它似乎与以下内容冲突:
\newtheorem*{definition}{Definition}
以及我的其他未编号的东西。
答案1
问题
\makeatletter
\renewcommand{\thetheorem}{\thesubsection.\arabic{theorem}}% Update counter printing
\@addtoreset{theorem}{subsection}% Reset theorem counter with every new subsection
\makeatother
在开始新的、\subsection
想要重新编号的地方之前。
\documentclass{article}
\newtheorem{theorem}{Theorem}[section]
\newtheorem{lemma}[theorem]{Lemma}
\newtheorem{corollary}[theorem]{Corollary}
\begin{document}
\section{First}
\subsection{first}
\begin{lemma}
$1+1=2$.
\end{lemma}
\begin{theorem}
$2+2=4$.
\end{theorem}
\makeatletter
\renewcommand{\thetheorem}{\thesubsection.\arabic{theorem}}% Update counter printing
\@addtoreset{theorem}{subsection}% Reset theorem counter with every new subsection
\makeatother
\subsection{second}
\begin{theorem}
$3+2=5$.
\end{theorem}
\end{document}
答案2
我认为这不是一个好主意。我希望你不想回到第一种枚举风格。
\documentclass{article}
\usepackage{chngcntr}
\begin{document}
\newtheorem{theorem}{Theorem}[section]
\newtheorem{lemma}[theorem]{Lemma}
\newtheorem{corollary}[theorem]{Corollary}
\section{First}
\subsection{first}
\begin{lemma}
$1+1=2$.
\end{lemma}
\begin{theorem}
$2+2=4$.
\end{theorem}
\subsection{second}
\counterwithin{theorem}{subsection}
\setcounter{theorem}{0}
\begin{theorem}
$3+2=5$.
\end{theorem}
\end{document}
答案3
如果您不需要对最后一部分进行连续编号,如您的示例所示,那么新的newtheorem
可能是最简单的解决方案。
\documentclass{article}
\begin{document}
\newtheorem{theorem}{Theorem}[section]
\newtheorem{lemma}[theorem]{Lemma}
\newtheorem{corollary}[theorem]{Corollary}
\section{First}
\subsection{first}
\begin{theorem}
2+2=4.
\end{theorem}
\subsection{second}
\newtheorem{theo}{Theorem}[subsection]
\begin{theo}
2+2=4.
\end{theo}
\end{document}