Monday, October 26, 2015

Continuous figure/table numbering in LaTeX

Link.


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}

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}

See the documentation for more information on the chngcntr package.

No comments:

Post a Comment