# Floats in the middle of paragraphs

How would you place a float like this with LaTeX?

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.

-
All questions should include a Minimal Working Example to make it easier to help and to demonstrate what you've tried so far. –  cfr Apr 10 '14 at 23:44
@cfr, I'm as keen on seeing MWEs as others, but really, I have tried nothing, so there's nothing I'm withholding. I've unsuccessfully tried to find solutions for this many years ago, but now I thought that maybe today, with all advancements in the TeX world there is some good way to do this. So what have I tried so far? Just looking at the somewhat related UK FAQ tex.ac.uk/cgi-bin/texfaq2html?label=textflow , but seen that there is really nothing there (and that answer is a bit old). –  pst Apr 11 '14 at 0:01
The pullquote examples here use 2column but the basic idea is the same the image is set at a fixed vertical position and text pours past it: tex.stackexchange.com/a/49294/1090 –  David Carlisle Apr 11 '14 at 0:19
@DavidCarlisle, Thanks, that looks very interesting! –  pst Apr 11 '14 at 0:35
@pst Still, some lines of code, even if it's a minimal non working example, are welcome. At least you save us from setting a default document. Now we have something in the answers, but it would be great to have something in the question. It's easier to copy the code than start from scratch. –  Manuel Apr 11 '14 at 0:45

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.

\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}

-
Wonderful! The main drawback which I notice (and which isn't a big deal) is that since \textfloatsep is split the float comes a bit close to the text. If this is the only kind of float you use, then you can of course just double \textfloatsep. –  pst Apr 11 '14 at 9:34
For those who want to use this I should add that I think values less than "0.5" often gives a betterlooking result. (As usual in typography we prefer placement in the upper half. And yes, I know it was me who wrote "in the middle of the page"…) I think the main reason to have these floats instead of topfloats is to have the floats more "enclosed", especially when there is a running head as in the example in my question. I suspect the typesetter for that had put the figure slightly higher up if it weren't for the paragraph break two lines above it, avoiding an orphan-like effect. –  pst Apr 11 '14 at 9:49
Is there a way to easily create a new kind of float? Instead of replacing t, say, that I could ask latex to do [!tbc]. If not, does it work locally if you enclose it in a \begingroup … \endgroup? –  Manuel Apr 11 '14 at 10:45
@pst wait for latex3:-) –  David Carlisle Apr 11 '14 at 11:22
@pst detecting widows/orphans would be pretty near impossible (unless you restrict to luatex) as by the time you get the page box to vsplit all internal structure is unavailable to the macro layer. –  David Carlisle Apr 11 '14 at 11:25

Something more like this?

The White Rabbit will always appear on page 2 in the centre of the page scaled to 37.5% of \textheight, taking 40% total including a little breathing room. Other pages are formatted much as usual:

This uses flowfram. This drastically changes the way TeX outputs text and may not suit your purposes depending on the other content of your document.

Caveat emptor.

\documentclass[a4paper]{article}
\usepackage{geometry}
\usepackage{flowfram, kantlipsum, graphicx}
\newflowframe*[ 1,>2 ]{ \textwidth }{ \textheight }{ 0pt }{ 0pt }[ mainflowframe ]
\newflowframe*[ 2 ]{ \textwidth }{ .3\textheight }{ 0pt }{ .7\textheight }[ secondflow ]
\newstaticframe*[ 2 ]{ \textwidth }{ .4\textheight }{ 0pt }{ .3\textheight }[ myflowfram ]
\newflowframe*[ 2 ]{ \textwidth }{ .3\textheight }{ 0pt }{ 0pt }[ firstflow ]
\setstaticcontents*{ myflowfram }{\centering\includegraphics[height=.375\textheight]{i019}\par}
\setallflowframes{ border=none }
\setallstaticframes{ border=none }

\begin{document}
\kant[1-20]
\end{document}

-
The problem (I think) with everything that uses \parshape is that it's about the shape of one paragraph and not about the total textflow. If there is a paragraph break in the text that's supposed to go past the float it won't work the same. –  pst Apr 11 '14 at 0:26
@pst Now I've seen your edited question and comments, I realise this isn't what you had in mind. That was not obvious when I started work on this. flowfram will do what you want but at some cost which is why I avoided it. It would help to know more about the overall project. –  cfr Apr 11 '14 at 0:29
@pst \parshape doesn't have to be restricted to a single paragraph I don't know this package but many packages automatically re-caculate the parshape for the remaining paragraph if the current one has not used up all the specified lines. –  David Carlisle Apr 11 '14 at 0:34
@DavidCarlisle, Thanks, that was an erroneous assumption from me, because of some effects I've seen. (I tried using short paragraphs in the text in this example before my comment, and it sort of collapsed.) –  pst Apr 11 '14 at 0:39
@pst look at wrapfig it doesn't do the fixed position but it has code to allow multiple paragraphs to use up a parshape (internally constructing new parshapes at each paragraph) –  David Carlisle Apr 11 '14 at 0:42

Using the insbox set of generic macros, it reduces to using the \InsertBoxC command if there is no caption. This command can be used anywhere in a paragraph: at the point of insertion, the macro first ends the line with the following text, then inserts what you want to insert, and ends with the rest of the paragraph.

If there is caption is more mysterious to me; using captionofafter \InsertBoxC has the effect that the line is not ended, and the rest of the paragraph appears as a new paragraph after the inserted box.

However there is a workaround: put the whole (\includegraphics and \captionof) in a tabular environment, \captionof being inside a \parbox. So here is a code that seems to produce what the O.P. requires:

\documentclass[11pt]{article}
\usepackage{graphicx}
\usepackage{caption}
\usepackage{cleveref,color}
\input{insbox}
\usepackage{cleveref}

\begin{document}

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec varius dapibus metus eget ultrices.
Nulla sagittis mauris rutrum, blandit augue eget, laoreet augue. Phasellus enim odio, sagittis in
mi sed, fringilla mollis odio. Phasellus quis purus ultricies, tempor purus at, tempus quam.%[height = 5cm]
Donec ultricies, ligula ac pretium porttitor, nibh nunc % <- command inserted here
Integer eros nibh, cursus at est sed, volutpat tristique justo. Donec ornare facilisis lorem, id
feugiat elit pellentesque at. Nulla odio mauris, luctus sed faucibus id, dignissim dictum velit.
Morbi vehicula velit at massa tristique rhoncus. Donec id ipsum molestie, pharetra augue sed,
rhoncus ligula. Cf.  \textcolor{red}{\cref{WhiteRabbit}}.

\end{document}


-
Can be useful when you know where in the text you want the float, and it's no problem if that's in the middle of a paragraph. But it won't do the absolute positioning on the page. –  pst Apr 11 '14 at 1:46
@pst: Yes, that' another philosophy. It has the merit of simplicity, as compared to flowfram that I used once to typeset recipes. Can you have a caption and cross-reference it? –  Bernard Apr 11 '14 at 1:53

The float package will do this. Use the [H] option for the float.

\documentclass{article}

\usepackage{float}
\usepackage{tikz}

\begin{document}

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec varius dapibus metus eget ultrices.
Nulla sagittis mauris rutrum, blandit augue eget, laoreet augue. Phasellus enim odio, sagittis in
mi sed, fringilla mollis odio. Phasellus quis purus ultricies, tempor purus at, tempus quam.
Donec ultricies, ligula ac pretium porttitor, nibh nunc
\begin{figure}[H]
\begin{tikzpicture}
\draw (0,0) rectangle (10,10);
\end{tikzpicture}
\end{figure}\noindent
accumsan neque, eget lacinia lacus massa eu leo.
Integer eros nibh, cursus at est sed, volutpat tristique justo. Donec ornare facilisis lorem, id
feugiat elit pellentesque at. Nulla odio mauris, luctus sed faucibus id, dignissim dictum velit.
Morbi vehicula velit at massa tristique rhoncus. Donec id ipsum molestie, pharetra augue sed,
rhoncus ligula. Proin eros orci, tristique lobortis lobortis non, gravida sit amet magna.

\end{document}

-
That is between paragraphs. –  pst Apr 11 '14 at 0:02
It's not. I just happen to place it after a dot. You could place the float wherever you want. –  David Kristiansen Apr 11 '14 at 0:05
Sorry, but that's still between two paragraphs, regardless of whether you let the second paragraph start with a small letter or not be indented. –  pst Apr 11 '14 at 0:09
I moved the float, and added a \noindent after it. That was reason, I think, you saw it as two paragraphs. –  David Kristiansen Apr 11 '14 at 0:09
The OP wanted the float to be fixed on the page not in the text flow, ie specify the float is in the centre of the page and have the text flow past it, –  David Carlisle Apr 11 '14 at 0:15