![禁用特定章节子节中的公式编号](https://linux22.com/image/371460/%E7%A6%81%E7%94%A8%E7%89%B9%E5%AE%9A%E7%AB%A0%E8%8A%82%E5%AD%90%E8%8A%82%E4%B8%AD%E7%9A%84%E5%85%AC%E5%BC%8F%E7%BC%96%E5%8F%B7.png)
我的文档结构是这样的,我通常希望每个部分和子部分都有公式编号计数器。问题是我不会在某个部分内有子部分,这会在该部分内的公式编号中引入额外的零。我目前正在使用这个chngcntr
包:
\usepackage{chngcntr}
\counterwithin{equation}{section}
\counterwithin{equation}{subsection}
有没有什么方法可以禁用某个部分内的方程式编号?
答案1
你应该把
\renewcommand{\theequation}{\thesection.\arabic{equation}}
在该部分的开头
\renewcommand{\theequation}{\thesubsection.\arabic{equation}}
在下一个之前。无需重新定义它是否会用 a 重置\subsection
,因为无论如何它都会用 a 重置\section
。
答案2
重新定义节与小节的技巧:
\documentclass{article}
\usepackage{amsmath}
\numberwithin{equation}{subsection}
\global\let\oldsection\section
\global\let\oldthesubsection\thesubsection
\xdef\oldeqnum{0}
\makeatletter
\def\section{%
\xdef\mdepth{1}
\gdef\thesubsection{\thesection}
\@ifstar{\@Starred}{\@nonStarred}%
}
\def\@Starred{%
\setcounter{equation}{\oldeqnum}
\@ifnextchar[%
{\GenericWarning{}{Warning: A starred section can not have parameters. I am going to ignore them!}\@StarredWith}%
{\@StarredWithout}%
}
\def\@StarredWith[#1]#2{%
\oldsection*{#2}%
}
\def\@StarredWithout#1{
\oldsection*{#1}%
}
\def\@nonStarred{%
\@ifnextchar[%
{\@nonStarredWith}%
{\@nonStarredWithout}%
}
\def\@nonStarredWith[#1]#2{%
\oldsection[#1]{#2}%
}
\def\@nonStarredWithout#1{%
\oldsection{#1}%
}
\let\oldsubsection\subsection
\def\subsection{%
\ifnum\mdepth=1
\xdef\oldeqnum{\the\value{equation}}\fi
\xdef\mdepth{2}
\gdef\thesubsection{\oldthesubsection}
\@ifstar{\@Starreds}{\@nonStarreds}%
}
\def\@Starreds{%
\@ifnextchar[%
{\GenericWarning{}{Warning: A starred section can not have parameters. I am going to ignore them!}\@StarredWiths}%
{\@StarredWithouts}%
}
\def\@StarredWiths[#1]#2{%
\oldsubsection*{#2}%
}
\def\@StarredWithouts#1{
\oldsubsection*{#1}%
}
\def\@nonStarreds{%
\@ifnextchar[%
{\@nonStarredWiths}%
{\@nonStarredWithouts}%
}
\def\@nonStarredWiths[#1]#2{%
\oldsubsection[#1]{#2}%
}
\def\@nonStarredWithouts#1{%
\oldsubsection{#1}%
}
\makeatother
\begin{document}
\section{No subsection here}
\begin{equation}
f(x)=0
\end{equation}
\begin{equation}
g(x)=0
\end{equation}
\section{With subsection here after first equation}
\begin{equation}
f(x)=0
\end{equation}
\subsection{Test subsection 1}
\begin{equation}
g(x)=0
\end{equation}
\section{With subsection here}
\begin{equation}
F(x)=0
\end{equation}
\subsection{Test subsection 2}
\begin{equation}
f(x)=0
\end{equation}
\begin{equation}
g(x)=0
\end{equation}
\subsection{Test subsection 3}
\begin{equation}
F(x)=0
\end{equation}
\begin{equation}
f(x)=0
\end{equation}
\begin{equation}
g(x)=0
\end{equation}
\begin{equation}
h(x)=0
\end{equation}
\section*{Continue numbering as section 3}
\begin{equation}
f(x)=0
\end{equation}
\begin{equation}
g(x)=0
\end{equation}
\end{document}
输出:
如您所见,您可以使用组合,并可以通过带星号的部分返回上一节的编号
使用了我的这个答案: