[Tex/LaTex] Section-level equation numbers follow previous section numbering

equationsmath-modenumbering

I am using \numberwithin{equation}{subsection} to number my equations uniquely for each subsection in my article.

For example:

  1. Section 1 Title

1.1 Subsection 1.1 Title

a=b (1.1.1)

a+2=b+2 (1.1.2)

  1. Section 2 Title

r=y (1.0.1)

However, in my document, I am not getting the right equation number for the first equation in the new section. The actual equation number sequentially follows the equation from the previous section. From the example above, r=y would be numbered 1.0.3.

Equations in the subsections below section 2 (i.e. 2.1 with equation 2.1.1) are numbered correctly.

Shouldn't the sections re-set the counter automatically?

Best Answer

In addition to the instruction

\numberwithin{equation}{subsection} 

you need the instructions

\makeatletter
\@addtoreset{equation}{section}
\makeatother

The first instruction, \numberwithin{equation}{subsection}, resets the equation counter only when a \subsection instruction is encountered. If you have a \section instruction but no \subsection instruction, the counter named equation is not reset unless you provide an additional instruction, such as \@addtoreset{equation}{section}.

enter image description here

Do note that if you do want to number the equations by subsection, it's probably not a good idea to feature equations between a \section directive and that section's first \subsection instruction: at that stage, the subsection counter is still 0 (having been reset to 0 by the \section directive), leading the equation numbers to be formatted as "2.0.1" and quite likely making your readers wonder if the subsection numbered 2.0 has somehow vanished mysteriously.

\documentclass{article}

\usepackage{amsmath} 
\numberwithin{equation}{subsection} 
\makeatletter
\@addtoreset{equation}{section}
\makeatother

\begin{document}

\section{Section 1 Title}
\subsection{Subsection 1.1 Title}

\begin{equation} a = b \end{equation}
\begin{equation} a+2=b+2 \end{equation}

\section{Section 2 Title}
%%\subsection{Subsection 2.1 Title}

\begin{equation} r=y \end{equation}

\end{document}