# Figures enumeration in wrong order

is there a way to enumerate figures in the order they actually appear in the document, and not in the order they were declared in the source file?

I have the following source:

\documentclass{article}
\usepackage{float}
\begin{document}
TEXT1
\begin{figure}[p]
\caption{Figur A}
\end{figure}
TEXT2
\begin{figure}[H]
\caption{Figur B}
\end{figure}
TEXT3
\end{document}


which yields the following two pages:

TEXT1
TEXT2

+++++++++++++++
+             +
+   FIGUR B   +
+             +
+++++++++++++++
Fig 2: Figur B

TEXT3

---new page---

+++++++++++++++
+             +
+   FIGUR A   +
+             +
+++++++++++++++
Fig 1: Figur A


So, how these two figures appear is exactly what I want, but it is really bad that in the output document, figure 2 comes before figure 1. This is also ugly in the table of figures:

Fig 2 "Figur B" page 1
Fig 1 "Figur A" page 2


What I want is, that iff tex decides to put figure B after figure A, then it should give figure B the number 1 and figure A the number 2.
I know there are some dirty hacks (setcounter; move figures in source), but obviously I'd like to have an elegant solution.

Thanks!

• Welcome to TeX.SX. I don't think you get the claimed output. Please, show a minimal example starting from \documentclass up to \end{document}. And if you're using [H] instead of [h], then it's well explained in the documentation of float that [H] can make the numbering of floats out of order. – egreg Feb 20 '18 at 9:47
• latex never makes figures float out of order, something is really wrong if the input that you show has the effect that you say it has. – David Carlisle Feb 20 '18 at 9:52
• @Sadret Well, the issue with the [H] specifier is clearly explained in the manual. – egreg Feb 21 '18 at 10:27
• I suppose your newly-updated code provides one more poignant example of why using the H placement specifier can be utterly counterproductive. For sure, if you replace H with ht!, "Figur B" will be placed after, not before, "Figur A". – Mico Feb 21 '18 at 10:27
• if you insist in use of [H] regardless, that you know, that its use leads to your problem, than go ahead and add \clearpage before \begin{figure}[H]. – Zarko Feb 21 '18 at 11:57

Under normal circumstances, LaTeX always outputs floats of a given type -- say, figure -- in the sequence in which they are encountered in the document. However, the H location specifier falls outside of "normal" circumstances. To achieve its objective, H deliberately steps outside of what is normal.
• Don't use the [H] location specifier. Consider using [ht!] instead.
• Or, as @Zarko has already commented, if you insist on using [H] anyway, be prepared to insert \clearpage before typing \begin{figure}[H].