texblog

Continuous figure/table numbering in LaTeX

In the standard document classes report and book, figure and table counters are reset after every chapter. On the other hand, article does not reset these counters when a new section is started. The chngcntr package provides the \counterwithin and \counterwithout commands to redefine a counter, by adding or removing a dependency. Through these commands, the behavior of the figure and table counters can be changed.

 
Continuous figure and table numbering in report/book

The \counterwithout command removes a dependency from a counter and redefines \the’counter’ such that it is printed without the dependency.

Through \counterwithout, the figure and table counters can be changed to continuously number these figures and tables throughout a report or book. The command also redefines the way the counter is printed, such that the chapter number is not shown (e.g. ‘Figure 3’ instead of ‘Figure 1.3′). Redefining \the’counter’ can be omitted through the starred version \counterwithout*.

\usepackage{chngcntr}

\counterwithout{figure}{chapter}
\counterwithout{table}{chapter}

This is what it looks like in the list-of-figures. Chapter headings were added to make it clear where a new chapter is started.

Below is a complete minimal working example.

\documentclass[11pt]{report}
\usepackage{chngcntr}
\counterwithout{figure}{chapter}

\newcommand*\dummyFigure[2]{%
	\begin{figure}[ht]\centering\rule{0.4\linewidth}{0.4\linewidth}\caption{#1}\label{#2}\end{figure}
}

\begin{document}
\listoffigures
\chapter{A dummy chapter}
\dummyFigure{A figure}{fig1}
\chapter{Another dummy chapter}
\dummyFigure{Another figure}{fig2}
\end{document}

 
Per-section figure and table numbering in article

Similarly, a reset-dependency can be added to any counter through \counterwithin. The command also redefines \the’counter’ (e.g. ‘Figure 1.3’ instead of ‘Figure 1’). Again, the package provides a starred version \conterwithin* that does not redefine \the’counter’.

As an example, the \counterwithin command can be used to automatically reset the figure and table counters whenever a new section is started in an article. Also, the command redefines \thefigure to \thesection.\arabic{figure}. Therefore, figure 3 in section 1 will be printed as ‘Figure 1.3’. The same applies to \thetable.

\usepackage{chngcntr}

\counterwithin{figure}{section}
\counterwithin{table}{section}

See the documentation for more information on the chngcntr package.

Exit mobile version