Assign numbering of theorems to figures

How can I assign numbering of theorems to numbering of figures? I have a certain figure and instead of it being called Figure 2.1: Figure for Theorem 2.2, it would be much batter to have it simply named Figure 2.2, so readers don't get confused.

There probably won't be more than one pictures for a single theorem, but just in case something unexpected happens in my document, is it possible to (either manually or automatic) add (a), (b), etc. after the caption?

Alternatively, I wouldn't mind adding captions completely manually (so I'd type the whole "Figure 2.2." thing myself)... How can I achieve this?

• I can think of problems with this approach. For instance, what if you have pictures that are not associated with a theorem? Wouldn't that mess up the numbering scheme? You may be better off creating a new type of float dedicated to illustrating theorems... May 4, 2013 at 15:37
• Just to clarify: Your figures might end up being numbered 2.2 followed by 2.5 because they're associated with theorems 2.2 and 2.5? Is there a chance that there will be figures not associated with theorems?
– Mico
May 4, 2013 at 15:38

Is this what you want?

\documentclass{amsart}
\usepackage{amsthm}
\newtheorem{theorem}{Theorem}
\makeatletter
\let\oldfig\thefigure%
\newcommand{\thmfig}[2][]{%
\renewcommand{\figurename}{Figure for Theorem}%
\renewcommand{\thefigure}{\ref{#2}}%
\caption{#1}
}
\renewcommand{\thefigure}{\oldfig}%
\makeatother
\usepackage[demo]{graphicx}
\usepackage{lipsum}
\begin{document}
\begin{theorem}[Pythagoras] \label{thm:pythagoras}
For a right triangle ABC, right angled at $A$, $a^2 = b^2 + c^2$.
\end{theorem}

\begin{figure}[htbp]
\includegraphics[width = 0.4\textwidth]{pyth}
\thmfig{thm:pythagoras}
\end{figure}
\lipsum[1]
\begin{figure}[htbp]
\includegraphics[width = 0.4\textwidth]{pyth}
\caption{Figure not associated to a theorem}
\end{figure}

\begin{theorem}[Pythagoras] \label{thm:rectsq}
All squares are rectangles.
\end{theorem}

\begin{figure}[htbp]
\includegraphics[width = 0.4\textwidth]{play}
\thmfig[Rectangle but not a square]{thm:rectsq}
\end{figure}

\end{document}


Output

• I believe not. The OP wants to change the number of figure according to the number of a theorem which it is related. May 4, 2013 at 15:54
• Oh! Sorry! I'll now write up an answer which is relevant.
– kan
May 4, 2013 at 15:56
– kan
May 5, 2013 at 18:02

Overview.

My approach was to create a new counter and variable to hold the existing figure counter value and figure label format respectively. The format can then be temporarily changed to the desired style and the value of the figure counter temporarily reset to 0, so that local numbering and styling, specific to the theorem can be implemented.

This is accomplished via a new environment, where, before the environment is finalized, the existing figure value and styles are re-applied as if nothing has changed.

The figures inside the theorem have their number preceded by the 'T/' so that it is easy to distinguish the association to the theorem, and Theorem 1 will have figures named Figure T/1-1, Figure T/1-2, Figure T/1-3 etc., by this token, a single theorem can have more than one figure.

Standard preamble.

\documentclass[10pt,a4paper]{article}
\usepackage{lipsum}
\usepackage[latin1]{inputenc}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{amsthm}
\usepackage[demo]{graphicx}


The Custom Environment.

\newtheorem{thm}{Theorem}
\newcounter{oldfigure}
\newenvironment{mythm}{
\setcounter{oldfigure}{\value{figure}}
\thm
\setcounter{figure}{0}
\let\theoldfigure\thefigure
\renewcommand{\thefigure}{T/\thethm-\arabic{figure}}
}{
\let\thefigure\theoldfigure
\endthm
\setcounter{figure}{\value{oldfigure}}
}


Dummy Document, Demonstrating the number and style being changed and re-applied.

\begin{document}
\figure[h]
\centering
\includegraphics[width = 0.4\textwidth,height=30pt]{figure}
\caption{My Figure}
\endfigure

\hrule
\begin{mythm}
\lipsum[2]
\figure[h]
\centering
\includegraphics[width = 0.4\textwidth,height=30pt]{figure}
\caption{My Figure}
\vspace{10pt}
\includegraphics[width = 0.4\textwidth,height=30pt]{figure}
\caption{My Figure}
\endfigure
\lipsum[2]
\end{mythm}
\hrule

\figure[h]
\centering
\includegraphics[width = 0.4\textwidth,height=30pt]{figure}
\caption{My Figure}
\endfigure
\end{document}


Sample Output.