我的乳胶代码:
\documentclass{article}
\usepackage{amsmath}
\renewcommand{\theequation}{\thesection.\arabic{equation}}
\makeatletter
\numberwithin{equation}{section}
\numberwithin{equation}{subsection}
\makeatother
\begin{document}
\section{First Section}
\subsection{Subsection A}
\begin{equation}
E = mc^2
\end{equation}
\subsection{Subsection B}
\begin{equation}
F = ma
\end{equation}
\section{Second Section}
\begin{equation}
a^2 + b^2 = c^2
\end{equation}
\end{document}
电流输出
1 First Section
1.1 Subsection A
E = mc2 (1.1.1)
1.2 Subsection B
F = ma (1.2.1)
2 Second Section
a2 + b2 = c2 (2.0.1)
但所需的输出是
1 First Section
1.1 Subsection A
E = mc2 (1.1.1)
1.2 Subsection B
F = ma (1.2.1)
2 Second Section
a2 + b2 = c2 (2.1)
答案1
以下解决方案满足了 OP 的要求,即,显示subsection
复合方程数中计数器的值除非该值等于零——如果\section
有指令但\subsection
最近没有发布任何指令,就会出现这种情况。
\documentclass{article}
\usepackage{amsmath} % for \numberwithin macro
\numberwithin{equation}{subsection}
\let\origtheequation\theequation % store the default format
\renewcommand{\theequation}{%
\ifnum\value{subsection}>0 \origtheequation % use default format
\else \thesection.\arabic{equation} % use a simplified format
\fi}
\setlength\textwidth{3.5in} % just for this example
\begin{document}
\section{First Section}
\subsection{Subsection A}
Some words\dots
\begin{equation} E = mc^2 \end{equation}
\subsection{Subsection B}
Some words\dots
\begin{equation} F = ma \end{equation}
\section{Second Section}
Some words\dots
\begin{equation} a^2 + b^2 = c^2 \end{equation}
\end{document}