# Section-level equation numbers follow previous section numbering

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?

• Welcome to TeX.SE. Inferring/guessing what your code may be doing, I am unable to produce an equation number "1.0.1" for the third equation ("r=y"). Instead, I get "2.0.3". Please post your code so that pointless guesswork may be eliminated. – Mico Apr 8 '15 at 3:53

\numberwithin{equation}{subsection}


you need the instructions

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

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

\begin{document}

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

$$a = b$$
$$a+2=b+2$$

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

$$r=y$$

\end{document}


You also can do it with the changcntr package:

\documentclass{article}

\usepackage{amsmath}
\usepackage{chngcntr}

\counterwithin{equation}{section}
\counterwithin{equation}{subsection}

\begin{document}

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

$$a = b$$
$$a+2=b+2$$

\section{Section 2 Title}

$$r=y$$

\subsection{Subsection 2.1 Title}

$$r + s=y + z$$

\end{document}