[Tex/LaTex] wrapfigure environment vspace above figure

floatsspacingwrapfigure

I am trying to use wrapfigure to place a figure within my document and I have noticed something odd occurring.

Code:

\documentclass{article}
\usepackage{lipsum,tikz,wrapfig}
\begin{document}    
\begin{wrapfigure}[9]{r}{4cm}
    \begin{tikzpicture}
        \fill (0, 0) rectangle (4, 4);
    \end{tikzpicture}   
\end{wrapfigure}
\lipsum[1]
\vspace{5mm}
\begin{wrapfigure}[10]{r}{4cm}
    \begin{tikzpicture}
        \fill (0, 0) rectangle (4, 4);
    \end{tikzpicture}   
\end{wrapfigure}
\lipsum[1]
\lipsum[1]
\end{document}

Output:

enter image description here

The first figure wraps correctly and as expected, however the second figure seems to have dropped down by a line. Why is this happening and how can I stop it?

Best Answer

The output is precisely what's expected, at least judging from the code.

You can remove the space by setting \intextsep:

\documentclass{article}
\usepackage{lipsum,tikz,wrapfig}

\setlength\intextsep{0pt}

\begin{document}    

\begin{wrapfigure}{r}{4cm}
    \begin{tikzpicture}
        \fill (0, 0) rectangle (4, 4);
    \end{tikzpicture}   
\end{wrapfigure}

\lipsum[1]

\begin{wrapfigure}{r}{4cm}
    \begin{tikzpicture}
        \fill (0, 0) rectangle (4, 4);
    \end{tikzpicture}   
\end{wrapfigure}

\vspace{5mm}
\lipsum[1-2]
\end{document}

enter image description here