2

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

\newtheorem{teo}{Theorem}[section]
\newtheorem{ex}[teo]{Example}

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
5

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
\newtheorem{teo}[figure]{Theorem}
\newtheorem{ex}[figure]{Example}

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:

\documentclass{amsart}
\numberwithin{figure}{section}
\newtheorem{teo}[figure]{Theorem}
\newtheorem{ex}[figure]{Example}

\begin{document}

\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}.

\end{document}
  • 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 2 days ago
  • @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 2 days ago
  • 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 2 days ago
2

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

enter image description here

\documentclass{report}

\usepackage{amsthm}
\newtheorem{teo}{Theorem}[section]
\newtheorem{ex}[teo]{Example}

\usepackage{xassoccnt}
\DeclareCoupledCounters[name=figurteo]{figure,teo}
\renewcommand\thefigure{\thesection.\arabic{figure}}

% just to allow 4 floats on a page:
\setcounter{totalnumber}{4}
\setcounter{topnumber}{4}

\begin{document}

% just for this example
\setcounter{chapter}{2}
\setcounter{section}{3}

\begin{teo}In the beginning, \dots \end{teo}
\begin{teo}After a while, \dots\end{teo}
\begin{figure}[ht]\caption{Fee}\end{figure}
\begin{figure}[ht]\caption{Fi}\end{figure}
\begin{figure}[ht]\caption{Fo}\end{figure}
\begin{figure}[ht]\caption{Fum}\end{figure}
\begin{ex}And then, \dots\end{ex}
\begin{ex}Finally, \dots\end{ex}

\end{document}

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.