1

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.

5
  • 1
    Figures are always numbered independently from theorem-like environments. Do you really want to change this standard?
    – yo'
    Aug 11, 2014 at 18:24
  • 2
    Moreover, figures are floats, while theorems are not. So, you may end up with a different order in terms of the numbering and the actual placement of content on the page.
    – Werner
    Aug 11, 2014 at 18:57
  • The only way is to get around the issue Werner stated is drop the floating feature of figure
    – user31729
    Aug 11, 2014 at 22:01
  • 1
    @tohecz Well, if figures are always numbered independently, then maybe I don't want to change that standard. Although I do like the fact that everything in my paper is enumerated and can be found based on the number of the current object. So if I reference a figure, I know exactly where it can be found. I've found that this simplifies everything greatly! Why doesn't everyone do that??
    – Bark Jr.
    Aug 11, 2014 at 22:08
  • @tohecz Additionally, the standard way of doing it seems to give two different figures the same call number. I have two Figure 2.4's in my paper (in two different sections: one in 2.4 and one in 2.7 ... I assume this is incorrect and not standard, right??
    – Bark Jr.
    Aug 11, 2014 at 22:34

2 Answers 2

1

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

2
  • Oh my gosh! Wonderful. Thank you! Additionally, is there any way to get the above to be Theorem 1.1.1, Figure 1.1.2, Theorem 1.1.3, Figure 1.1.4, etc... ?
    – Bark Jr.
    Aug 11, 2014 at 22:32
  • @BarkJr.Sure, just comment out @\addtoreset{figure}{theorem} or delete that line completely. The figure number will be reset then per chapter or per section, that depends on the class settings
    – user31729
    Aug 11, 2014 at 22:36
1

I was searching for the same thing and the answer is a bit simpler I think. With my Method it doesn't matter if you use the figure environment or not.

  1. You need to overwrite of the figure Counter to be a theorem counter:
    \renewcommand{\thefigure}{\thesection.\arabic{theorem}}
  2. you need to raise the theorem counter by one before you use captionof or caption: \stepcounter{theorem} or \addtocounter{theorem}{1} \

\thefigure is calling on the figure counter and you basically overwrite the counter. \thesection is there for the 1.1, because the theorem counter is also displayed that way, and the \arabic{theorem} ist just printing the theorem counter. if you use a \begin{theorem} the counter automatically raises itself but it doesn't with figures, when you just call upon it, that's why you have to raise it yourself, when you use a figure. so in total:

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

\renewcommand{\thefigure}{\thesection.\arabic{theorem}}%IMPORTANT

\begin{document}

\chapter{My first chapter}

\section{The very first section}%

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

\begin{figure}[h]
\centering
\stepcounter{theorem}%IMPORTANT
\includegraphics{somefig}
\caption{The Figure}
\end{figure}

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

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


\end{document}

enter image description here

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .