21

I'm using wrapfig to put a small figure at the start of each paragraph. For the first paragraph of the page, this lines up neatly with the top of the text. But for subsequent paragraphs, the figure lines up with the second line:

\documentclass{article}

\usepackage{lipsum, wrapfig}

\begin{document}
\begin{wrapfigure}{l}[1cm]{2cm}\rule{2cm}{2.67cm}\end{wrapfigure}
\lipsum[1]

\begin{wrapfigure}{l}[1cm]{2cm}\rule{2cm}{2.67cm}\end{wrapfigure}
\lipsum[3]

\end{document}

gives

Two paragraphs, the first with correct wrapfig vertical alignment, the second with a mysterious space.

The second box here should line up with "Nulla" (not "lutpat") in the same way as the first does with "Lorem".

Using the optional argument to specify the number of shortened lines does not change the actual picture placement at all. Nor does \raisebox, although I'm not sure why. And nor does placing the wrapfigure environment any earlier in the text (obviously not possible with lipsum, but I've tried putting this environment at several places through the preceding paragraph with no effect on the position of the figure).

This document is actually being typeset in LuaLaTeX, to use both ttf fonts and microtype, but the error is reproducible in pdfLaTeX (e.g., the MWE above). Obviously an automagic answer would be best, but there are sufficiently few of these pictures that a solution involving tweaking some length by hand would still be very helpful.

1

1 Answer 1

23

The explanation I give here is simply an extended version of the answer given some time ago by Ulrike Fischer in Wrapped figure diverges from text level after sections.

The wrapfigure package adds the length \intextsep to the figure and this length is responsible for the odd behaviour (the first figure dosn't get affected because \intextsep has no effect at the beginning of the page). One possible solution would be to set this length to 0pt; you have to be careful, though, since \intextsep is also used for other floats, so setting it globally to 0pt might have undesired effects. Here's a local redefinition of the length:

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

\begin{document}

\begingroup
\setlength\intextsep{0pt}
\begin{wrapfigure}{l}[1cm]{2cm}\rule{2cm}{2.67cm}\end{wrapfigure}
\lipsum[1]
\endgroup

\begingroup
\setlength\intextsep{0pt}
\begin{wrapfigure}{l}[1cm]{2cm}\rule{2cm}{2.67cm}\end{wrapfigure}
\lipsum[3]
\endgroup

\end{document}

enter image description here

5
  • Many thanks for this---which worked like a charm---and apologies for not spotting the duplicate!
    – Ant
    Sep 6, 2011 at 21:20
  • 3
    Um, this doesn't work for me at all. If I wrap it in the group, the figure drops to the end of the line, and if I don't, the reset has no effect. Has something happened in 5 years? Feb 25, 2016 at 1:40
  • 2
    @JoannaBryson you (always) needed a paragraph break before the end of group (\lipsum adds one) Aug 11, 2016 at 12:50
  • @DavidCarlisle's suggestion worked for me. Using the above solution, my text was overlaying the figures. Adding a paragraph break (blank line) did the trick! Nov 1, 2017 at 7:12
  • It didn't work for me :( as a result, the text simply won't wrap around the figure anymore. Any advice? Feb 10, 2018 at 19:43

You must log in to answer this question.

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