[Tex/LaTex] Reset equation numbering after each section

countersequationsnumbering

I would like to reset equation numbering after each section or subsection. Right now I use

\setcounter{equation}{0}

I saw in another page you could also reset it by adding the following line to the preamble.

\numberwithin{equation}{subsection}
\renewcommand\theequation{\arabic{equation}}

But this doesn't seem to work. The equation counters just increment across subsections. It's the same across sections if we changed the preamble to

\numberwithin{equation}{section}

Best Answer

Tell LaTeX to reset the equation number whenever section or subsection is stepped:

\documentclass{article}

\usepackage{chngcntr}

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

\begin{document}
\section{One}
\begin{equation} 2+2=3.99      \end{equation}
\begin{equation} \pi^2=9.86    \end{equation}

\section{Two}
\begin{equation} E=mc^2        \end{equation}
\begin{equation} v=\frac{e}{t} \end{equation}

\subsection{Two \& One}
\begin{equation} 2+2=22 \end{equation}
\end{document}

Same as Fran's image

The instruction \counterwithin* is (almost) an interface to \@addtoreset (which is better not used if a higher level command provided by a package is available). With \counterwithin (without *) the counter's representation would be changed, which isn't with the *-form.