我正在为一个主题写笔记(我正在使用documentclass{report}
)。在我的项目中,我遵循章节 - 部分 - 小节的布局。我想以如下形式对章节、部分和小节的标题进行编号
Chapter 1. ABC
1.1. ABC
1.1.1. ABC.
1.1.2. ABC.
1.2. ABC
1.2.1. ABC.
所以我实现了这些代码
% for chapter
\usepackage{sectsty}
\renewcommand{\thechapter}{\arabic{chapter}.}
\newlength\mylength
\renewcommand\cftchappresnum{\large{\hspace{0.04cm}}}
\settowidth\mylength{\bfseries\cftchappresnum\cftchapaftersnum}
\addtolength\cftchapnumwidth{\mylength}
% for section
\renewcommand{\thesection}{\arabic{chapter}.\arabic{section}}
\renewcommand{\cftsecnumwidth}{2em}
\titleformat*{\section}{\LARGE\bfseries}
% for subsection
\renewcommand{\thesubsection}{\arabic{chapter}.\arabic{section}.\arabic{subsection}.\hspace{-.55cm} }
\titleformat*{\subsection}{\large\bfseries}
但是,当我使用 align 环境时,方程的标签只会像 (1..1)。我希望方程的标签遵循这样的模式
Chapter 1.
Section 1.1.
Equation (1.1)
Equation (1.2)
Subsection 1.1.1.
Equation (1.1.1)
Equation (1.1.2)
Subsection 1.1.2.
Equation (1.1.3)
Equation (1.1.4)
Section 1.2.
Equation (1.3)
Equation (1.4)
Subsection 1.2.
Equation (1.2.1)
Equation (1.2.2)
我该怎么做?谢谢。
答案1
因为在 中包含了一个点,所以会得到..
方程式编号\thechapter
。要删除它,\theequation
请像对\thesection
或所做的那样重新定义\thesubsection
:
\renewcommand*{\theequation}{\arabic{chapter}.\arabic{equation}}
您的方程编号方案看起来有点奇怪,因为您在第一个中重新初始化方程计数器\subsection
,在下一个中继续,但在下一个中返回\section
,这次继续第一个编号。
您需要在第一个子节中保存用于节的计数器值。为此创建一个新的计数器
\newcounter{PreviousSectionEquation}[chapter]
并添加一个钩子到\subsections
:
\AddToHook{cmd/subsection/before}{%
\ifnum\value{subsection} = 0\relax% first subsection
\setcounter{PreviousSectionEquation}{\value{equation}}%
\setcounter{equation}{0}%
\fi%
\renewcommand*{\theequation}{\thesection.\arabic{equation}}
}
这将在第一个子部分中保存方程计数器,然后再重新初始化。它还会进行\theequation
相应的设置。
添加另一个钩子来\section
取回 的值PreviousSectionEquation
(如果已设置),并重置\theequation
:
\AddToHook{cmd/section/before}{%
\ifnum\value{PreviousSectionEquation} > 0\relax%
\setcounter{equation}{\value{PreviousSectionEquation}}%
\setcounter{PreviousSectionEquation}{0}%
\fi
\renewcommand*{\theequation}{\arabic{chapter}.\arabic{equation}}
}
完整代码(没有不必要的非编译内容):
\documentclass{report}
% for chapter
\renewcommand{\thechapter}{\arabic{chapter}.}
% for section
\renewcommand{\thesection}{\arabic{chapter}.\arabic{section}}
% for subsection
\renewcommand{\thesubsection}{\arabic{chapter}.\arabic{section}.\arabic{subsection}.\hspace{-.55cm} }
%% special equation numbering
\newcounter{PreviousSectionEquation}[chapter]
\AddToHook{cmd/section/before}{%
\ifnum\value{PreviousSectionEquation} > 0\relax%
\setcounter{equation}{\value{PreviousSectionEquation}}%
\setcounter{PreviousSectionEquation}{0}%
\fi
\renewcommand*{\theequation}{\arabic{chapter}.\arabic{equation}}
}
\AddToHook{cmd/subsection/before}{%
\ifnum\value{subsection} = 0\relax% first subsection
\setcounter{PreviousSectionEquation}{\value{equation}}%
\setcounter{equation}{0}%
\fi%
\renewcommand*{\theequation}{\thesection.\arabic{equation}}
}
\begin{document}
\chapter{A Chapter}
\section{Section 1.1.}
\begin{equation} Equation~(1.1) \end{equation}
\begin{equation} Equation~(1.2) \end{equation}
\subsection{Subsection 1.1.1.}
\begin{equation} Equation~(1.1.1) \end{equation}
\begin{equation} Equation~(1.1.2) \end{equation}
\subsection{Subsection 1.1.2.}
\begin{equation} Equation~(1.1.3) \end{equation}
\begin{equation} Equation~(1.1.4) \end{equation}
\section{Section 1.2.}
\begin{equation} Equation~(1.3) \end{equation}
\begin{equation} Equation~(1.4) \end{equation}
\subsection{Subsection 1.2.}
\begin{equation} Equation~(1.2.1) \end{equation}
\begin{equation} Equation~(1.2.2) \end{equation}
\end{document}