[Tex/LaTex] Floats in the middle of paragraphs

floatspositioning

How would you place a float like this with LaTeX?

enter image description here

Note that it's in the middle of a sentence. Normal float placement rules could only find the right page to put the float on. Then it's a matter of where on the page it's visually pleasing, regardless of where paragraph breaks happen to be. I think a placement in the middle of the page like this often looks better than at the top or bottom of the page, even though it perhaps has fallen out of style. (This example is printed in 1926.)

Added: The point is not that the float should be in the middle of a paragraph. The float is at a predetermined position on the page. The point is instead that that could be in the middle of a paragraph.

Best Answer

This modifies LaTeX's top float positioning so that it puts the top floats in the centre of the page, or at least as close to the centre as possible, if the text flow has a an unbreakable box or math display at the centre the vsplit will not split it at exactly the centre. It's not extensively tested but it works on this page:-). It applies to all top floats in the document.

enter image description here

\documentclass{article}
\usepackage{kantlipsum}


\makeatletter

\def \@cflt{%
    \let \@elt \@comflelt
    \setbox\@tempboxa \vbox{}%
    \@toplist
\setbox\z@\vsplit\@outputbox to 0.5\ht\@outputbox
    \setbox\@outputbox \vbox{%
                             \boxmaxdepth \maxdepth
                             \unvbox\z@
                             \vskip .5\textfloatsep
                             \unvbox\@tempboxa
                             \vskip -\floatsep
                             \topfigrule
                             \vskip .5\textfloatsep
                             \unvbox\@outputbox
                             }%
    \let\@elt\relax
    \xdef\@freelist{\@freelist\@toplist}%
    \global\let\@toplist\@empty
}

\makeatother

\begin{document}
\kant[1-5]

\begin{figure}[t]

\rule{3cm}{6cm}

\caption{a rectangle}
\end{figure}

\kant[2-7]

\end{document}
Related Question