1

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?

1
  • 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
    Commented Apr 8, 2015 at 3:53

2 Answers 2

1

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

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}

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

\section{Section 2 Title}

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

\subsection{Subsection 2.1 Title}

\begin{equation} r + s=y + z\end{equation}

\end{document} 

enter image description here

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .