AnswerBun.com

wrapfigure: Several text-wrapped figures in the same block of text

TeX - LaTeX Asked by Anne Morbach on December 4, 2020

I would like to “scatter” several pictures throughout the same block of text with wrapfig.

MWE:

documentclass{scrreprt}

usepackage{graphicx, wrapfig}
usepackage{lipsum}

begin{document}

begin{wrapfigure}[12]{l}{0.4textwidth}
    includegraphics[width=0.4textwidth]{example-image-a}\
end{wrapfigure}
begin{wrapfigure}[12]{r}{0.4textwidth}
    includegraphics[width=0.4textwidth]{example-image-b}\
end{wrapfigure}

lipsum[1-3]

end{document}

This only treats the last figure as a figure wrapped in text. The first one is “ignored” and placed above the text.
This image shows what LaTeX gives me vs. what I want:

enter image description here

2 Answers

First, the wrapping can't overlap because wrapfig has no mechanism to combine multiple shapes. This example does not quite overlap though.

I expected all you would need to do is place the second wrapfig within the paragraph between the correct words, exactly as @Vincent comments. But that doesn't work -- wrapfig gives a warning and floats the figure anyway. Thinking more, this makes sense: wrapfig doesn't know that the wrapping has finished until the paragraph is ended because the text is not broken into lines until the end of the paragraph. I suppose wrapfig could end the paragraph just to test, but if it does decide to float the figure then it has ended the paragraph unnecessarily.

So the solution is to explicitly do what wrapfig does implicitly to start wrapping in the middle of a paragraph: insert

setlengthparfillskip{0pt}parsetlengthparfillskip{0pt plus 1fil}

in the paragraph, between two words where the natural line-break occurs, followed by begin{wrapfig}.... (Vincent probably said this solution too.)

documentclass{scrreprt}

usepackage{graphicx, wrapfig}
usepackage{lipsum}

begin{document}
setlengthintextsep{0pt}

begin{wrapfigure}{l}{0.4textwidth}
    includegraphics[width=linewidth]{example-image-a}
end{wrapfigure}
The hottest day of the summer so far was drawing to a close and a drowsy
silence lay over the large, square houses of Privet Drive. Cars that were
usually gleaming stood dusty in their drives and lawns that were once emerald
green lay parched and yellowing--for the use of hosepipes had been banned due
to drought. Deprived of their usual car-washing and lawn-mowing pursuits, the
inhabitants of Privet Drive had retreated into the shade of their cool houses,
windows thrown wide in the%
setlengthparfillskip{0pt}parsetlengthparfillskip{0pt plus 1fil}
begin{wrapfigure}{r}{0.4textwidth}
    includegraphics[width=linewidth]{example-image-b}
end{wrapfigure}
noindent
hope of tempting in a nonexistent breeze. The only
person left outdoors was a teenage boy who was lying flat on his back in a
flowerbed outside number four.

He was a skinny, black-haired, bespectacled boy who had the pinched, slightly
unhealthy look of someone who has grown a lot in a short space of time. His
jeans were torn and dirty, his T-shirt baggy and faded, and the soles of his
trainers were peeling away from the uppers. Harry Potter's appearance did not
endear him to the neighbours, who were the sort of people who thought
scruffiness ought to be punishable by law, but as he had hidden himself behind
a large hydrangea bush this evening he was quite invisible to passers-by. In
fact, the only way he would be spotted was if his Uncle Vernon or Aunt Petunia
stuck their heads out of the living-room window and looked straight down into
the flowerbed below.


end{document}

Correct answer by Donald Arseneau on December 4, 2020

You need to scatter the figures in the text also.

documentclass{scrreprt}
usepackage{graphicx, wrapfig}
usepackage{lipsum}

begin{document}

begin{wrapfigure}[10]{l}{0.4textwidth}
    includegraphics[width=0.4textwidth]{example-image-a}
end{wrapfigure}

LipsumPar{1}

begin{wrapfigure}[11]{r}{0.4textwidth}
    includegraphics[width=0.4textwidth]{example-image-b}
end{wrapfigure}

LipsumPar{2}
LipsumPar{3}

end{document}

Answered by Vincent on December 4, 2020

Add your own answers!

Related Questions

Missing # inserted in tabular mode

1  Asked on January 1, 2021 by pedro-baptista

     

Indent text after line break in itemize enviroment

1  Asked on January 1, 2021 by martin-schmitz

     

Why is nsim thicker than sim?

3  Asked on December 31, 2020 by jukka-suomela

   

New command to turn to italics

1  Asked on December 31, 2020 by andy-toff

 

Grammarly for texstudio

3  Asked on December 31, 2020 by hamid

   

write the content of an hbox in an auxilary file

1  Asked on December 31, 2020 by maeul

   

Any idea how to get this kind of format?

2  Asked on December 31, 2020 by christian-bartholomew

         

Resize the whole table to fit linewidth, not just the tabular

3  Asked on December 31, 2020 by miroslav-palansk

 

How to change the text placement on edge Tikz

2  Asked on December 31, 2020 by aziz

   

Ask a Question

Get help from others!

© 2022 AnswerBun.com. All rights reserved. Sites we Love: PCI Database, MenuIva, UKBizDB, Menu Kuliner, Sharing RPP, SolveDir