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:
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
Get help from others!
Recent Questions
Recent Answers
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP