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

TeemoJg
  • 883

2 Answers2

4

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 Apr 16 '19 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. –  Apr 16 '19 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 '19 at 23:21
1

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}
Mico
  • 506,678