如何修改公式编号的外观

如何修改公式编号的外观

我的乳胶代码:

\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}

相关内容