[Tex/LaTex] How to get figure counter to follow theorem counter

floatsnumbering

I am trying to get my figure to counter to follow my theorem counter. I created a few different environments: lemma, example, definitions, etc. I have gotten all of them to follow my theorem counter.

The numbering goes Chapter.Section.theorem. So it will go like this:

Chapter 2 "The Second Chapter"

Section 2.1 The First Section

Definition 2.1.1 – First Definition

Theorem 2.1.2 – The First Theorem

Section 2.2 The Second Section

Chapter 3 "The Third Chapter"

etc…

However, the figures don't seem to follow the counter. The first figure (in section 2.4) is number Figure 2.3 … So I'm trying to get it to fall in line with the rest so that it would look like:

Example 3.2.5 – The Example

Figure 3.2.6 – The Figure for Example 3.2.5

Any suggestions? I put all the code that I think is applicable below. Let me know if you need more/something else…

\documentclass{thesis} %This is my school's self-made document class

\newtheorem{theorem}{Theorem}[section]
\newtheorem{corollary}[theorem]{Corollary}
\newtheorem{definition}[theorem]{Definition}
\newtheorem{lemma}[theorem]{Lemma}
\newtheorem{proposition}[theorem]{Proposition}

\theoremstyle{definition}   %Added by me
\newtheorem{example}[theorem]{Example}

%\makeatletter  %Added by me
%\let\c@theorem\c@figure
%\makeatother

\begin{document}

\begin{figure}
\caption{The Figure}
\end{figure}

\end{document}

I've attempted the \let\c@theorem\c@figure but that doesn't seem to work.

Best Answer

A proposition:

  1. Don't use floating figures, remove \begin{figure}...\end{figure} around the graphics and caption
  2. Use caption package and \captionof{figure}{foo text} instead of standard \caption command
  3. Redefine the figure output command \thefigure to obtain the \thetheorem.\arabic{figure} output
  4. (Optional) Use a resetting of figure counter by theorem, i.e. @addtoreset{figure}{theorem} If this is not wanted, just comment that line

\documentclass{book} % can't use thesis.cls here, since unknown!!!

\usepackage{caption}%
\usepackage[demo]{graphicx}%
\usepackage{amsthm}%

\newtheorem{theorem}{Theorem}[section]
\newtheorem{corollary}[theorem]{Corollary}
\newtheorem{definition}[theorem]{Definition}
\newtheorem{lemma}[theorem]{Lemma}
\newtheorem{proposition}[theorem]{Proposition}

\theoremstyle{definition}   %Added by me
\newtheorem{example}[theorem]{Example}

%\makeatletter  %Added by me
%\let\c@theorem\c@figure
%\makeatother

\makeatletter
\@addtoreset{figure}{theorem}
\makeatother

\let\StandardTheFigure\thefigure
\renewcommand{\thefigure}{\thetheorem.\arabic{figure}}

\begin{document}

\chapter{My first chapter}

\section{The very first section}%

\begin{theorem}
\( E = m c^2 \)
\end{theorem}

\begin{center}
\includegraphics{somefig}
\captionof{figure}{The Figure}
\end{center}

\begin{theorem}
\( E^2 = p^2 c^2 + \left({m c^2}\right)^2 \)
\end{theorem}

\begin{center}
\includegraphics{somefig}
\captionof{figure}{Another figure}%
\end{center}


\end{document}

enter image description here

Related Question