# Numbering figures

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.

-
But this can be confusing since figures wrote with the figure environment might float away from the point where you wrote them in the code. –  Gonzalo Medina May 20 '12 at 2:31
Your question's aim is ambiguous: Do you want figures to share the same counter as equations, or do you just want a figure's number to be rendered in the same way as an equation's number is? I would assume it's the latter. If that's correct and the amsmath package is loaded, all you need to do is issue the command \numberwithin{figure}{section}. –  Mico May 20 '12 at 5:07

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}

$$a=b$$

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

$$c=d$$

\end{document}


-

You want to use the same counter for figures as you use for equations? Here's one solution:

\documentclass{article}
\makeatletter
% \dupcntr{slave}{master} has the slave counter be an alias for the master counter
\newcommand*{\dupcntr}[2]{%
\expandafter\let\csname c@#1\expandafter\endcsname\csname c@#2\endcsname
}
\dupcntr{figure}{equation}
\renewcommand\thefigure{\theequation}
\makeatother
\begin{document}

% snip

\end{document}


The solution was borrowed from a TeX stackexchange discussion on Slave Duplicate Counters

-