Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In LaTeX, is there a way to put a float automatically after where it is first referenced?

Tags:

latex

figures

I am currently writing a long one-column document that contains a lot of floats (figures and tables). I know the usual b/h/p/t options for placing floats in latex. However, I was wondering if there exists a package or macro that would let me do the following automatically: place a float automatically right after it was first reference. So if the reference appears on the top of page x, then the float would most likely appear at the bottom of page x, or maybe at (the top of) page x+1. In any case it should not occur before the reference.

I know that this may be hard to achieve but then I am not a latex guru either...

(Note that this question is different from this one.)

like image 864
user66237 Avatar asked Feb 13 '09 20:02

user66237


People also ask

What does HTBP mean in LaTeX?

Easing the float placement by options: You could use more positioning options. Not just [h] . If you wish to place the figure near, allow more positioning options, for instance by [htbp] (here, top, bottom, page).

How do you make a float in LaTeX?

The short answer: use the “float” package and then the [H] option for your figure. The longer answer: The default behaviour of figures is to float, so that LaTeX can find the best way to arrange them in your document and make it look better.

How do you make a figure stay in place in overleaf?

In general text you can force a LaTeX image to stay where it is placed in the code using the [! h] command in the figure environment.

How do I keep figures together in LaTeX?

The trick is to use \ContinuedFloat from the subfig package. As you can see in page 5 of package documentation, It sometimes occurs, especially when using sub-floats, that a single figure needs to be continued across pages.


1 Answers

The LaTeX Companion says that the flafter package can be used to ensure that floats are never placed before their references. To use this, add the following to your document's preamble:

\usepackage{flafter}

Note that, according to this thread, what flafter does is ensure that the float never appears before its position in the LaTeX source code.

This may work well if your document only has a few floats. For documents with lots of floats, placement becomes much more difficult, and you may find that all your floats appear together at the end of the document or chapter, or you may receive a "Too many unprocessed floats” error. I suggest reading this page and this page in the UK TeX FAQ for more suggestions.

like image 67
ChrisN Avatar answered Oct 09 '22 13:10

ChrisN