You can use \LoopResetCounters
from xassoccnt
which sets all counters given in the comma-separated list to zero.
See the update for grabbing all counters defined with \newcounter
and put them on a list at the end of this answer!
\documentclass{article}
\usepackage{xassoccnt}
\begin{document}
\setcounter{figure}{17}
\thefigure
\LoopResetCounters{page,section,subsection,figure,equation,subsubsection,table}
\thefigure
\end{document}
Update
I've grabbed the comment by David Carlisle and exploited the \cl@@ckpt
list in order to reset the all counters to -1
, but omitted the page
counter there!
In order to make the resetting list work, the \@stpelt
list must be changed at all.
No additional package is needed at all!
This procedure does not influence the secnumdepth
and tocdepth
counters since those are not defined with \newcount
.
\documentclass{article}
\makeatletter
\newif\if@resetall
\@resetallfalse
\let\latex@newcounter\newcounter
\newcommand{\ResetAllCounters}[1][-1]{%
\EnableResetAll
\def\@elt##1{%
\def\@tmp@@a{##1}
\def\@tmp@@b{page}
\ifx\@tmp@@a\@tmp@@b % Check if it is the page counter
\setcounter{##1}{\z@}%
\else
\setcounter{##1}{#1}%
\fi
}%
\cl@@ckpt% Loop through the list of all counters defined with \newcounter
\gdef\@@resetvalue{#1}% Store the reset value
}
% Redefine the reset stepper \@elt - list marker
\let\latex@@stpelt\@stpelt
\def\@stpelt#1{%
\if@resetall%
\global\csname c@#1\endcsname \numexpr\@@resetvalue-1\stepcounter{#1}
\else
\latex@@stpelt{#1}%
\fi
}%
\newcommand{\DisableResetAll}{%
\global\@resetallfalse
}
\newcommand{\EnableResetAll}{%
\global\@resetalltrue%
}
\setcounter{secnumdepth}{5}
\setcounter{tocdepth}{5}
\makeatother
\begin{document}
\tableofcontents
\part{Foo}
\section{Foo}
\ResetAllCounters
\part{Foostuff}
\section{Foostuff}
\subsection{Foostuff subsection}
\subsubsection{Foostuff subsubsection}
\paragraph{Foostuff paragraph}
\subparagraph{Foostuff subparagraph}
\part{Foobar}
\section{Foobar}
\subsection{Foobar subsection}
\subsubsection{Foobar subsubsection}
\paragraph{Foobar paragraph}
\subparagraph{Foobar subparagraph}
\ResetAllCounters
\DisableResetAll
\part{Barstuff}
\section{Barstuff}
\subsection{Barstuff subsection}
\subsubsection{Barstuff subsubsection}
\paragraph{Barstuff paragraph}
\subparagraph{Barstuff subparagraph}
\end{document}

\newcounter
command initalizes any counter with0
. The packagetotcount
does initialize total counters however with-1
. If somebody did not make errors in the class/package setup, this should not be a real issue. If there's a proper\newcounter{foo}[bar]
statement, the counters on the reset list are set to zero as soon as the driver counter is increased with\stepcounter
or\refstepcounter
.totcount
package initializes total counters with -1, and if I understand correctly, the "total counters" are an addition of that package to count up the number of items of a thing? If yes, then what is the relevance/connection of total counters to counters, especially given the original question?totcount
package.page
counter starts at -1 because I set it to the list explicitly.