2


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!

Sadret
  • 121
  • 7
    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 09:47
  • 4
    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 09:52
  • Sorry, I forgot to include that i am using \usepackage{float} with H option. I edited the question. – Sadret Feb 21 '18 at 10:21
  • 1
    @Sadret Well, the issue with the [H] specifier is clearly explained in the manual. – egreg Feb 21 '18 at 10:27
  • 2
    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
  • @egreg Sure, but that doesn't solve the problem / answers the question. – Sadret Feb 21 '18 at 11:53
  • @Mico But that is not really what I want. There is a reason I use [H]. – Sadret Feb 21 '18 at 11:54
  • 1
    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

1 Answers1

3

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.

There are only two possible remedies:

  • 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].

Mico
  • 506,678