Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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.

share|improve this question
2  
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
2  
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

2 Answers 2

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

share|improve this 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

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.