Wrapfigure: skip some lines

I am having a wrapfigure at the bottom of my page in the last paragraph which refuses a nice looking position.

x -> text, # -> wrapfigure:

xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx ##################################
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx ##################################
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx ######### some equation ##########
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx ##################################
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx ##################################
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx


Because the equation is relatively small, I do not want that much whitespace. I want the text to float under and above the wrapfigure, like this (the whole paragraph is 14 lines long, so there is enough space):

xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx ##################################
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx ######### some equation ##########
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx ##################################
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx


The wrapfigure (in the code) is above the paragraph and whenever I move it down in the paragraph (even in the middle of the first sentence) it instantly moves to the next page.

Code looks like this:

\begin{wrapfigure}[8]{R}{0.5\textwidth}
\begin{small}
\begin{gather}
I_{in} =
\begin{bmatrix}
46 & 42 & 50 \\
44 & 65 & 56 \\
41 & 52 & 58 \\
\end{bmatrix}
\\
I_{out}(2,2) = 131
\end{gather}
\end{small}
\end{wrapfigure}
% paragraph...

• What is the small environment? – Bernard Jun 27 '15 at 19:24
• The matrix (bmatrix) is perfectly readable in small text size and was a bit too big in normal text size...hence, I made the matrix small(er). – daniel451 Jun 27 '15 at 19:46
• Yes, but there is no ‘small’ environment in standard LaTeX, as far as I know. You have to use the \small switch. – Bernard Jun 27 '15 at 20:07
• I read this solution somewhere, I'm not remembering where it was. It was suggested, for long texts, math environments, ... to use \begin and \end to create a small environment. I could not tell if this is common practice...but it works^^ – daniel451 Jun 27 '15 at 22:44

2 Answers

You can what you want with the plaintex package insbox. It defines \InsertBoxL and \InsertBoxR commands, with two arguments: the number of untouched lines before inserting the box, and the contents of the box. Also an optional argument: the number of supplementary wrapped lines, if the height of the box is not correctly calculated.

\documentclass[12pt]{article}

\usepackage{mathtools}
\input{insbox.tex}
\usepackage{lipsum}

\begin{document}
\InsertBoxR{3}{%
\parbox{0.5\linewidth-4mm}{\small
\begin{gather}
I_\text{in} =
\begin{bmatrix}
46 & 42 & 50 \\
44 & 65 & 56 \\
41 & 52 & 58 \\
\end{bmatrix}
\\[0.5ex]
I_\text{out}(2,2) = 131
\end{gather}}}[2]%
Some text. Some more text. Some more text. Some more text. Some more text. Some more text. Some more text. Some more text. Some more text. Some more text. Some more text. Some more text. Some more text. Some more text. Some more text. Some more text.Some more text. Some more text. Some more text. Some more text. Some more text. Some more text. Some more text. Some more text. Some more text. Some more text. Some more text. Some more text. Some more text. Some more text. Some more text. Some more text.Some more text. Some more text. Some more text. Some more text. Some more text. Some more text. Some more text. Some more text.

\end{document}


• Nice solution. But the words bleed into the box, i.e at the line with I_{in} – user31729 Jun 27 '15 at 20:09
• @Christian Hupfer: I think it isn't related to insbox, only a hyphenation problem in the context of shorter lines and comparatively short word. Maybe a text in German would not show any problem :o) – Bernard Jun 27 '15 at 20:16
• It wasn't meant as criticism... Just noted it. And no, not any word in German can be hyphenated at will;-) – user31729 Jun 27 '15 at 20:19
• I didn't take it as a criticism. I just meant you have more possibilities for hyphenation with longer words. And the German language has on average longer words than, say, French, due to the structure of the language. I also might have chosen Cymric or Greek! – Bernard Jun 27 '15 at 20:26
• Looks like what I want, but pdftex says insbox.sty not found when I implement \usepackage{insbox}. Maybe the name of the package is wrong? I have texlive-full... – daniel451 Jun 27 '15 at 22:49

You can achieve this effect with wrapfig.sty. In its documentation, you find:

Placment and floating
Parameter #2 (required) is the figure placement code, but the valid codes are different from regular figures. They come in pairs: an uppercase version which allows the figure to float, and a lowercase version that puts the figure "exactly here". [...]
It is convenient to begin the environment between paragraphs, but if you want placement in the middle of a paragraph, you must put the environment between two words where there is a natural line break.

Replace R with r and find a natural line break in your paragraph to start with \begin{wrapfigure}. E.g.:

\documentclass{article}
\usepackage{lmodern,wrapfig,amsmath}
\begin{document}

Wrapfig.sty provides the environments wrapfigure and wraptable for
typesetting a narrow float at the edge of the text, and making the
text wrap around
\begin{wrapfigure}[8]{r}{0.5\textwidth}
\small
\begin{gather}
I_{in} =
\begin{bmatrix}
46 & 42 & 50 \\
44 & 65 & 56 \\
41 & 52 & 58 \\
\end{bmatrix}
\\
I_{out}(2,2) = 131
\end{gather}
\end{wrapfigure}
it. The wrapfigure and wraptable environments interact properly with
the \verb|\caption| command to produce proper numbering, but they are
not regular floats like figure and table, so (beware!)  they may be
printed out of sequence with the regular floats.  [...]  Parameter
\verb|#2| (required) is the figure placement code, but the valid codes
are different from regular figures. They come in pairs: an uppercase
version which allows the figure to float, and a lowercase version that
puts the figure exactly here''.
\end{document}