3

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.

  • 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
5

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

3

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

3

The package xassoccnt supports coupling and decoupling of multiple counters (not just two of them!) with \DeclareCoupledCounters under definition of a counter group name -- this is not using a 'shared' counter approach (a feature, that is not yet supported by xassoccnt)

\documentclass{book}


\usepackage{xassoccnt}

\DeclareCoupledCounters[name=figurequation]{figure,equation}


\begin{document}
\begin{equation}
  E=mc^2
\end{equation}

\begin{equation}
  c^2 = a^2 + b^2
\end{equation}

\begin{figure}[ht]
  \caption{Foo figure}
\end{figure}

\begin{figure}[ht]
  \caption{Foo figure}
\end{figure}

\begin{figure}[ht]
  \caption{Foo figure}
\end{figure}

\begin{figure}[ht]
  \caption{Foo figure}
\end{figure}

\begin{equation}
  c^2 = a^2 + b^2
\end{equation}



\end{document}

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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