# Continuous v. per-chapter/section numbering of figures, tables, and other document elements

Some document elements (e.g., figures in the book class) are numbered per chapter (figure 1.1, 1.2, 2.1, ...). How can I achieve continuous numbering (figure 1, 2, 3, ...)?

And vice versa: Some document elements (e.g., figures in the article class) are numbered continuously. How can I achieve per-section numbering?

\documentclass{book}% for "vice versa" variant, replace book with article

\begin{document}

\chapter{foo}% for "vice versa" variant, replace \chapter with \section

\begin{figure}
\centering
\rule{1cm}{1cm}% placeholder for graphic
\caption{A figure}
\end{figure}

\end{document}


Bonus question: Is it possible to adjust the numbering of the sectioning headings themselves? Can I, e.g., switch from per-chapter to continuous numbering of sections in the book class?

Changing the numbering of (e.g.) figures involves two modifications:

1. Redefining whether or not the figure counter will be reset whenever the chapter/section counter is incremented;

2. Redefining the "appearance" of the figure counter (\thefigure), i.e., removing (or adding) the chapter/section prefix.

## Standard solution: chngcntr

The standard solution – which deals with modifications 1 and 2 mentioned above – is to use the \counterwithout and \counterwithin macros of the chngcntr package. The following example shows how to achieve continuous figure numbering in the book class:

\documentclass{book}

\usepackage{chngcntr}
\counterwithout{figure}{chapter}

\begin{document}

\chapter{foo}

\begin{figure}
\centering
\rule{1cm}{1cm}% placeholder for graphic
\caption{A figure}
\end{figure}

\end{document}


Conversely, here's how to achieve per-section figure numbering in the article class:

\documentclass{article}

\usepackage{chngcntr}
\counterwithin{figure}{section}

\begin{document}

\section{foo}

\begin{figure}
\centering
\rule{1cm}{1cm}% placeholder for graphic
\caption{A figure}
\end{figure}

\end{document}


It works the same way for (e.g.) tables, custom-defined floats, equations, and footnotes. (Note that in many document classes featuring the \chapter command, footnotes are numbered per chapter even though the footnote counter does not show the chapter prefix.) The macros of chngcntr may also be used for theorem environments; it is easier, though, to specify the numbering of a new theorem environment when defining it:

\newtheorem{thm}{Theorem}% Continuous numbering
\newtheorem{prop}{Proposition}[section]% Per-section numbering


You may also customize the numbering of the sectioning headings themselves. To, say, accomplish continuous numbering of sections in the book class (by default, those are numbered per chapter), but per-part numbering of chapters (which are by default numbered continuously), your preamble should contain

\usepackage{chngcntr}
\counterwithout{section}{chapter}
\counterwithin{chapter}{part}


To influence the resetting of counters without changing their appearance, use the starred macro versions \counterwithout* and \counterwithin*. E.g., for per-section numbering of figures in the article class – but without attaching a section prefix to \thefigure –, add the following to your preamble:

\usepackage{chngcntr}
\counterwithin*{figure}{section}


It is also possible to redefine a counter's resetting and appearance any number of times in the document body. Note that \counterwithout, \counterwithin and their variants won't affect the counter's current value; to change the latter, use \setcounter{<counter>}{<new value>}.

## Other solutions

With the memoir class, one doesn't need to load chngcntr because memoir emulates the functionality of the package. Just use \counterwithout and \counterwithin as described above.

The AMS classes and the amsmath package feature the \numberwithin macro which matches chngcntrs \counterwithin. However, there is no AMS equivalent to \counterwithout.

The caption package features the key–value options figurewithin and tablewithin which allow to change the numbering of (surprise) figures and tables. Permitted option values are chapter, section, and none. (For the first code example above, this translates into \usepackage[figurewithin=none]{caption}.)

The listings package uses \AtBeginDocument to define the lstlisting counter of the environment of the same name. To turn off the environment's per-chapter numbering for classes that feature \chapter, issue \lstset{numberbychapter=false} in the document preamble. To enable per-section numbering for classes without \chapter, add the following to your preamble:

\usepackage{chngcntr}
\AtBeginDocument{\counterwithin{lstlisting}{section}}

• How would I use the amsmath's numberwithin to achieve this numbering style on all defined theoremstyles? Sorry if this is answered above and I am just missing it. – BBischof Nov 5 '11 at 16:54
• @BBischof When you say \newtheorem{thm}{Theorem}[chapter], the thm environment will be numbered in the form <chapter>.<theorem>; a following \newtheorem{lem}[thm]{Lemma} will use the same counter for lemmas as for theorems. – egreg Nov 15 '11 at 7:45
• @egreg I'm sorry, but I don't really understand your comment. It seems helpful, but I am a little confused. Could you be a bit more verbose? :/ – BBischof Nov 29 '11 at 13:44
• Can you add a package-free option here as well? Something using \@addtoreset? – Werner Jun 21 '16 at 18:34
• I believe since the 2018 release the macro \counterwithout is integrated in the LaTeX kernel. It might be worth updating the answer. – campa Mar 29 at 14:55

Patryk's answer works perfectly. But you need to reset the counter of tables, figures, equations, etc. manually every time you want to start your object labels at "1" again. So it would be more suitable for e.g. a paper with some appendices than for a book with many chapters.

The \renewcommand line you only have to set once.

The advantage is that it is super simple and flexible.

Like this:

\setcounter{figure}{0}
\renewcommand{\thefigure}{A\arabic{section}.\arabic{figure}}


To create "Figure A1.1"

You could also do

\renewcommand{\thefigure}{Appendix~\arabic{section}.\arabic{figure}}


to obtain "Figure Appendix 1.1" (if you would feel the urge).

Or

\renewcommand{\thefigure}{A\arabic{section}.\arabic{subsection}.\arabic{figure}}


to obtain "Figure A1.1.1" for Figure 1 in subsection 1 of section A1.

Strangely enough, no one mentioned the package remreset and its \@removefromreset macro or the LaTeX - core macro \@addtoreset yet.

See for another version with xassoccnt at the bottom of this post.

\documentclass{book}

\usepackage{remreset}
\makeatletter
\@removefromreset{figure}{chapter}
\renewcommand{\thefigure}{\arabic{figure}}

\makeatother

\begin{document}

\chapter{First}
\begin{figure}
\caption{First figure}
\end{figure}
\chapter{Second}

\begin{figure}
\caption{Second figure}
\end{figure}

\section{A section that causes resetting of figure}

\begin{figure}
\caption{Third figure}
\end{figure}

\end{document}


Using xassoccnt there is \RemoveFromReset and \AddToReset (without using \makeatletter...\makeatother

\documentclass{book}

\usepackage{xassoccnt}

\RemoveFromReset{figure}{chapter}
\renewcommand{\thefigure}{\arabic{figure}}

\begin{document}

\chapter{First}
\begin{figure}
\caption{First figure}
\end{figure}
\chapter{Second}

\begin{figure}
\caption{Second figure}
\end{figure}

\section{A section that causes resetting of figure}

\begin{figure}
\caption{Third figure}
\end{figure}

\end{document}


Please note that there is \RemoveFromFullReset as well, which removes the counter and its own reset list from the driver reset list.

Update Starting with version 1.3 of xassoccnt, \AddToReset, \RemoveFromReset support comma - separated list of counters to be added or removed from the driver counter reset list. Current version is 1.5, as of 2017/10/20.

You can also redefine thefigure command

\renewcommand{\thefigure}{\arabic{chapter}.\arabic{figure}}


and in article class

\renewcommand{\thefigure}{\arabic{section}.\arabic{figure}}

• Only redefining \thefigure` does nothing with regard to counter resetting and therefore may result, e.g., in figures in different chapters featuring the same name "Figure 1". – lockstep Oct 19 '14 at 17:11
• @Patryk, That worked awesome for me. Just as I wanted, I have Chapters in romans and I when I type an equation, it shows like (I.1), (Equation 1 for chapter I), when I did your command, I changed "\thefigure" for "\theequation" and "figure" for "equation" (in your first quote), and I got it just like I wanted, i.e. (1.1) (equation 1 for chapter I), without changing my chapters to arabic numbers. Thanks :) – Jorge V Oct 18 '15 at 3:35