[NTG-context] Float control

Alan Braslau alan.braslau at icloud.com
Thu Mar 2 03:35:01 CET 2023

On Thu, 2 Mar 2023 00:12:53 +0100
Hans Hagen via ntg-context <ntg-context at ntg.nl> wrote:

> On 2/28/2023 11:45 AM, Denis Maier via ntg-context wrote:
> > Hi everyone,
> > 
> > I’ve recently had to typeset a document that gave me some headaches
> > with the floats. The floats where jumping around, appearing in a
> > different order than in the source file, tables ended up split up
> > at weird points, some positioning keys had not the intended effect
> > (e.g. top), «page» moved the float more than seemed necessary for
> > me... I know, TeX’s float positioning algorithm should be rather
> > reliable and stable, and it’s quite possible that I’m messing
> > things up in my setups–especially since my source files are XML.
> > 
> > Anyway, I’d like to learn more about the whole float issue. Is
> > there anything particular I could read to learn more about the
> > whole thing? Maybe I’m missing out on something fundamental...
> Basically floats are output in order when they fit. You can use force
> to really do that. When there is no room they will migrate. Some
> options like top and bottom might also change the order. Normally you
> start with just placing ('here') and see how that works out. Side
> floats are special and anchored to the text.
> The more complex and confliuctign the demands, the harder it gets for 
> ConTeXt to fulfill all requirements. In that case shifting around the 
> text or places where you ask for a float helps. It's one of the areas 
> where 'fully automated and perfect' are complex as everything can 
> interfere.
> Btw, Mikael S is working on a tutorial that explains some neat
> trickery with specific placements (which also triggered some
> additional features).

A few (important) observations on floats:

triggers a paragraph break.

I therefore locate them always at the beginning or at the end of a
paragraph of text.
	(A trick is to enclose them in a named buffer within a
	paragraph, typically where a figure call -
	\in{figure}[figureReference] - is to be located. Then to place
	the \getbuffer at the beginning or end of a paragraph. See
	example below.)

The keys location=top/bottom will place the float at the top or bottom
of the page IF IT FITS, otherwise it is pushed to the following page.
Thus, a bottom can become a top.

The key location=force will place the figure there, perhaps generating
a page break if it does not fit.

The key location=page will put the figure on a following page. This
situation can sometimes push figures to appear "out of order", if
another figure can somehow fit before the figure pushed to the
following page. This happens if another floating figure "comes too

The keys location=left and location=right will also generate a page
break if the figure does not fit.

In the end, one needs to tweak a document in final form especially if
it contains many figures, unfortunately. This is done by moving the 
\startfigure...\stopfigure. Here, the use of buffers:

Paragraph text ...
(see \in{figure}[myfigure]).
More text ...\par

can make life easier, moving the \getbuffer[myfigure] to an optimal
paragraph beginning or end.


P.S. It might be nice to be able to anchor a figure not to text but to
a page location, like location=nexttop or location=nextbottom, or even
location={nexttop,right} etc. This gets really complicated (but
anything is do-able).

P.P.S. I'm certain to learn some neat trickery from Mikael's tutorial!

More information about the ntg-context mailing list