I when I create a command for (for example) the examples in my article, I do it in this way:


So the enumeration is consecuent to what I have done with the theorems and other things, but the figures do their own enumeration, how can I change that in the same way of the examples? Thanks

  • Exactly, for example, if there is a figure between theorem 2.3, and example 2.4, I want them to be, theorem 2.3, figure 2.4, and example 2.5 – J.Rodriguez Apr 16 at 3:31
  • Did you see this answer to the query Numbering figures? – Mico Apr 16 at 4:30

You can essentially use the same approach as in your MWE except that you use figure to number your theorems:

\numberwithin{figure}{section}% number figures inside sections

The \numberwithin command, which comes from amsmath, numbers the figures in tandem with the sections. Using this approach you can get the output

enter image description here

using the code:



\section{Let the section begin}

  \begin{teo}The sum of two numbers is a number\label{T:one}\end{teo}

  \begin{figure}[h]A figure\caption{Nice one}\label{F:one}\end{figure}

  \begin{ex}For example, $1+2=3$.\label{E:one}\end{ex}

  See \ref{T:one}, \ref{F:one} and \ref{E:one}.

  • This answer depends on the use of the amsart document class. But that's not necessary -- article plus amsthm gives the same result. – barbara beeton Apr 16 at 19:10
  • @barbarabeeton As the OP didn't provide a MWE with a document class I took the liberty of using my preferred article class, which is amsart. Using article and amsthm does not work as this gives an "Undefined control sequence" error for \numberwithin. Of course, you could use \makeatletter\@addtoreset{figure}{section}\makeatother with the article document class. – Andrew Apr 16 at 21:40
  • Ah! Forgot that. Easily fixed -- \usepackage{amsmath}. (Rash assumption -- if one is using amsthm, one is probably already using amsmath. Nice to hear that amsart is your favorite, but not everyone has the same preferences.) – barbara beeton Apr 16 at 23:21

Here's a solution that employs the xassoccnt package to couple the teo and figure counters.

enter image description here




% just to allow 4 floats on a page:


% just for this example

\begin{teo}In the beginning, \dots \end{teo}
\begin{teo}After a while, \dots\end{teo}
\begin{ex}And then, \dots\end{ex}
\begin{ex}Finally, \dots\end{ex}


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.