13

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?

3
  • Here, the problem disappears if there is text before the first figure.
    – Denis
    Jan 6, 2016 at 14:15
  • @Denis If there is text before the first figure then both are dropped down by 1 line, is there anyway to fix this without manually modifying the \vspace? Jan 6, 2016 at 14:45
  • You are completely right. I was only suggesting this to obtain an even look.
    – Denis
    Jan 6, 2016 at 14:53

3 Answers 3

11

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

2
  • What's the default value? Can we add or remove from it? Apr 4, 2018 at 17:15
  • @RaffiKhatchadourian It's a LaTeX parameter, so setting it might have adverse effects for other floats. Its default value is 12pt plus 2pt minus 2pt.
    – egreg
    Apr 4, 2018 at 17:19
2

A quick fix for this would be to use the \vspace{-fontsize} command to jump up by one line (change fontsize to the font size you are using).

\documentclass[11pt]{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}
    \vspace{-11pt}
    \begin{tikzpicture}
        \fill (0, 0) rectangle (4, 4);
    \end{tikzpicture}   
\end{wrapfigure}
\lipsum[1]
\end{document}

Output

enter image description here

1

With:

\documentclass[a4paper,12pt]{article}
\usepackage{lipsum,tikz,wrapfig}

\begin{document}
\mbox{}

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

\vspace{2mm}

\begin{wrapfigure}{r}{4cm}
    \begin{tikzpicture}
        \fill (0, 0) rectangle (4, 4);
    \end{tikzpicture}
\end{wrapfigure}
\lipsum[1]
\end{document} 

I am getting the following output that is visually correct: enter image description here

2
  • Isn't this exactly the opposite of what the OP is asking?
    – Rico
    Jan 6, 2016 at 14:37
  • @Rico Ooops... You are right. At least the two figures now wrap similarly.
    – Denis
    Jan 6, 2016 at 14:40

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .