47

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}
5
  • 3
    "doesn't work" isn't very informative, do you get an error? Have you got \subsections (the above won't reset at a \section) Oct 16 '14 at 20:00
  • Welcome to TeX.SX! You can have a look at our starter guide to familiarize yourself further with our format. A suggestion: Do us a favour and change your username to something more telling than "user1234". Oct 16 '14 at 20:06
  • I don't get an error. It just increments the counter even when moving across a new subsection. Oct 18 '14 at 4:11
  • 1
    This question is not a duplicate of Number equations like subsections. The earlier posting was concerned with setting up equation numbers so that they contain the section number automaticallz. This new question is about something different: How to execute the (equivalent of the) instruction \setcounter{equation}{0} every time a \section or \subsection directive is encountered.
    – Mico
    Oct 18 '14 at 9:58
  • 3
    If I understand your posting correctly, you may achieve your objective -- not having to manually execute \setcounter{equation}{0} at the start of each section and subsection -- by adding the following four instructions to the preamble: \makeatletter \@addtoreset{equation}{section} \@addtoreset{equation}{subsection} \makeatother. Note that this operation is quite different from what's achieved by executing \numberwithin{equation}{section} or \numberwithin{equation}{subsection}.
    – Mico
    Oct 18 '14 at 12:23
35

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.

11
  • Is something like this also possible within \align environments?
    – Taunch
    Jun 8 '16 at 9:04
  • @Taunch It should work out of the box
    – egreg
    Jun 8 '16 at 9:58
  • 1
    @egreg How would you reset the counter for \subsubsection*? Aug 29 '16 at 6:23
  • @YagnaPatel Not something that can go in a comment. Please, ask a new question with all details.
    – egreg
    Aug 29 '16 at 7:15
  • this don't work in the "report" environment how to do ? @egreg
    – Vrouvrou
    Feb 25 '19 at 20:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.