Is there a way to get LaTeX to place figures and tables in the order they are referenced in the text?
Asked Answered
B

4

5

I think this question is novel. Here is the problem I have. I have a relatively short piece of text associated with a lot of figures and a table. I want floats to appear on pages just for floats but in the order I specify. I have set all of the table and figure parameters to [hp] and placed them in the order I want them to appear in the source e.g.

Figure 1

Figure 2

Figure 3

Table 1

Figure 4

Figure 5

The problem I have is that no matter what I do the document typesets like this

Table 1

Figure 1

Figure 2

etc....

I have tried trashing the Aux files before typesetting. I am aware of the endfloats package but I still want latex to place the floats in between larger sections of txts in other parts of the document. Any help is greatly appreciated.

Biosphere answered 14/10, 2010 at 18:40 Comment(2)
See also: https://mcmap.net/q/564883/-in-latex-is-there-a-way-to-put-a-float-automatically-after-where-it-is-first-referencedSpendable
This belongs on tex.stackexchange.com nowadays.Episcopacy
T
10

I'll try to explain why the fix by @user476160 (placement modifier hp instead of just p) works. A figure is a float, i.e. an element that cannot be broken across a page. The figure environment accepts a parameter list with placement hints:

\begin{figure}[placement parameters]
% ...
\end{figure}

The placement specifier h stands for here and places the figure approximately at the same point as in the source text. The placement specifier p puts the figure in a special page that contains only floats:

\begin{figure}[hp]
% ...
\end{figure}

Wikibooks has an excellent article on figure placement if you want to fine-tune your figure and table placement.

I also recommend posting LaTeX-related questions in the TeX Stack Exchange Q&A.

Tetrameter answered 14/10, 2010 at 19:22 Comment(0)
B
2

Problem solved, the first figure in my list had the parameter [p] rather [hp]. This seemed to cause latex a lot of grief for some reason. Anyhow problem solved for now. The figures and txt all appear in the order I have specified.

Biosphere answered 14/10, 2010 at 18:49 Comment(0)
D
1

It is quite easy. All you have to do is use this package.

\usepackage{float}

And you have to change the figure parameters to

\begin{figure}{H}
%..
\end{figure]}

Let me know if it works :)

Dx answered 13/3, 2018 at 22:46 Comment(0)
J
0

Similar to what user8768298 said, first import the package in the preamble

\usepackage{float}

And then use improved version of user8768298's code:

\begin{figure}[H]
%..
\end{figure}

if you use table then try this:

\begin{table}[H]
%..
\end{table}

it works for me perfectly on Overleaf.

Joerg answered 26/10, 2024 at 17:8 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.