How to number floats in sequence with theorems?

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.

-

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.

-
Ah, thanks! I hadn't thought of using the float counter as the pre-existing one to latch all my theorems onto. I'd slightly prefer having the floats numbered as they appear, but that's not a big issue, especially as I do have plenty of text so it's unlikely to cause much confusion. –  Peter LeFanu Lumsdaine Nov 12 '10 at 2:35
If it continues to irk you, a separate question about renumbering floats might find someone who has a trick. (That person's not me, though, unless you want to overuse [hH].) –  Antal S-Z Nov 12 '10 at 2:41