[Tex/LaTex] Wrapfigure: skip some lines

pdftexpositioningwrapfigure

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...

Best Answer

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} 

enter image description here

Related Question