Skip to main content
To reset or set a LaTeX counter, write \setcounter{name}{0} (or another integer, such as \setcounter{section}{4} so the next \section is numbered 5). LaTeX tracks every automatic number—sections, equations, figures, tables, footnotes, and pages—in a named counter that you can change, format, or bind to another counter.

Resetting and changing counters with \setcounter

When LaTeX starts a numbered element such as \section or \begin{equation}, it increments that counter by 1 before printing it. To make the next element start at 1 again, reset the counter to 0 (\setcounter{equation}{0}); to make the next section start at 5, set \setcounter{section}{4}.
set-and-reset-counters.tex
Ready to use this syntax? Continue in the browser editor when you want to adapt the example in a real project.Open LaTeX Cloud Studio
All six core counter commands are built into base LaTeX:

Creating custom counters (\newcounter and \refstepcounter)

Pass an optional parent counter in square brackets to \newcounter{exercise}[section] so LaTeX resets exercise to 0 automatically at every \section. Creating a counter also defines \theexercise (defaulting to \arabic{exercise}), which you can redefine with \renewcommand. Inside custom numbered commands or environments that readers might reference with \label and \ref, always increment the counter with \refstepcounter rather than \stepcounter. \stepcounter increases the number without updating LaTeX’s internal reference target, so \label would point to the enclosing section instead.
newcounter-and-refstep.tex

Formatting counters and redefining \thesection

Six commands format a counter’s current value for printing, either directly in the text or inside \renewcommand{\the<counter>}{...}:
counter-formats.tex

Linking and unlinking resets (\counterwithin and \counterwithout)

To tie an existing counter to another counter—such as numbering equations per section (1.1, 1.2, then 2.1)—use \counterwithin{child}{parent}. To remove a built-in reset—such as continuous figure numbering across chapters in report or book—use \counterwithout{child}{parent}. Both commands have been built into the LaTeX kernel since the April 2018 release (loading the older chngcntr package is no longer needed). The unstarred forms also redefine \the<child> (\the<parent>.\arabic{<child>} for \counterwithin, and \arabic{<child>} for \counterwithout); append a star (\counterwithin*, \counterwithout*) to change only the reset dependency while leaving \the<child> unchanged.
counterwithin-example.tex

Standard LaTeX counters

Try it in the editor

All kernel counter commands, including \counterwithin and \counterwithout, are built into LaTeX Cloud Studio’s TeX Live 2026 (full distribution) environment. Start from the Basic Article template in LaTeX Cloud Studio and replace main.tex with the complete example.