[Tex/LaTex] How to number floats in sequence with theorems

floatsnumberingtheorems

I like having all my theorems, examples, defintions etc. numbered in a single sequence. Is it possible to have LaTeX number my floating figures in sequence with them as well? I.e.:

Theorem 1.1 A theorem!

(A pretty picture)
Fig. 1.2: caption.

Definition 1.3 A definition.

I presume this would be pretty difficult to implement because of how floats, well, float! But hopefully there's some clever package that does it. I'm using amsthm, so solutions compatible with that would be most useful, but I'm certainly still interested in other answers.

Best Answer

You can do this in a straightforward manner with amsthm; its \newtheorem command has the following syntax: \newtheorem{environment-name}[matched-counter]{text}[parent-counter]. Whatever counter is specified for matched-counter is used to number the created theorem; if none is given, a new counter is created. Thus, leveraging the existing figure counter, the following works:

\documentclass{amsart}
\usepackage{amsthm}

\newtheorem{theorem}[figure]{Theorem}
\newtheorem{definition}[figure]{Definition}

\begin{document}
  \begin{theorem}
    This is a theorem.
  \end{theorem}

  \begin{figure}
    \caption{This is a figure.}
  \end{figure}

  \begin{definition}
    This is a definition.
  \end{definition}
\end{document}

This will produce output along the lines of:

Figure 2. This is a figure.
Theorem 1. This is a theorem.
Definition 3. This is a definition.

So there is one obvious property of this which you might or might not like: figures are numbered as they are introduced in code, not as they appear. This is the standard behavior for figures, and would be less egregious if I actually had some text in my sample document, so I think it's relatively sensible. If you dislike it (as you allude to in your question), I'm not sure what to suggest. You could use the float placement [h], which tries to put the float exactly where it's specified in the source; however, TeX will still float it if it needs to. The float package provides an [H] float placement which unconditionally forces the (no-longer-floating) "float" to appear right there. Personally, I'd probably just let TeX number the floats as it wants to; from the text, the order of reference will probably be clear.

Related Question