[Tex/LaTex] Numbering figures

floatsnumbering

How do I get figure numbers to run in the same sequence as equation numbers, eg (1.2.3) equation …. figure 1.2.4? For the environments I define I use \newtheorem{thm}[equation]{THM}, but I don't know how to do the same trick with pre-defined environment like figure.

Best Answer

The required numbering scheme can be confusing since figures written using the figure environment might float away from the point where you wrote them in the code (see my example code below in which the numbers appear out of their natural order).

If you want this scheme, using, for example. the amsmath package and its \numberwithin command you can make the equation and figure counters tied to section numbering: then, with the help of the etoolbox package you can make the figure environment to increase the equation counter and viceversa:

\documentclass{book}
\usepackage{amsmath}
\usepackage{etoolbox}

\numberwithin{figure}{section}
\numberwithin{equation}{section}

\AtBeginEnvironment{figure}{\stepcounter{equation}}
\AtBeginEnvironment{equation}{\stepcounter{figure}}

\begin{document}

\chapter{Test}
\section{test}

\begin{equation}
a=b
\end{equation}

\begin{figure}
\centering
\rule{1cm}{1cm}% placeholder for `\includegraphics`
\caption{A test figure}
\label{fig:test}
\end{figure}

\begin{equation}
c=d
\end{equation}

\end{document}

enter image description here

Related Question