wrapfigure:同一文本块中的多个文本环绕图形

wrapfigure:同一文本块中的多个文本环绕图形

我想使用 wrapfig 将几张图片“分散”到同一文本块中。

梅威瑟:

\documentclass{scrreprt}

\usepackage{graphicx, wrapfig}
\usepackage{lipsum}

\begin{document}

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

\lipsum[1-3]

\end{document}

这只会将最后一个图形视为文本包裹的图形。第一个图形被“忽略”并放置在文本上方。此图显示了 LaTeX 提供的结果与我想要的结果:

在此处输入图片描述

答案1

首先,包裹不能重叠,因为 wrapfig 没有组合多个形状的机制。不过这个例子并没有完全重叠。

我以为你需要做的就是将第二个 wrapfig 放在段落中正确的单词之间,就像 @Vincent 评论的那样。但那行不通——wrapfig 会发出警告,并且无论如何都会浮动图形。仔细想想,这是有道理的:wrapfig 不会知道直到段落结束,换行才完成,因为文本直到段落结束才被分成几行。我想wrapfig可以结束该段落只是为了测试,但如果它确实决定浮动图形,那么它就不必要地结束了该段落。

因此,解决方案是明确执行 wrapfig 隐式执行的操作,以在段落中间开始换行:插入

\setlength\parfillskip{0pt}\par\setlength\parfillskip{0pt plus 1fil}

在段落中,在自然换行符出现的两个单词之间,后跟\begin{wrapfig}...。 (Vincent 可能也说过这个解决方案。)

\documentclass{scrreprt}

\usepackage{graphicx, wrapfig}
\usepackage{lipsum}

\begin{document}
\setlength\intextsep{0pt}

\begin{wrapfigure}{l}{0.4\textwidth}
    \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%
\setlength\parfillskip{0pt}\par\setlength\parfillskip{0pt plus 1fil}
\begin{wrapfigure}{r}{0.4\textwidth}
    \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}

答案2

您还需要将图形分散在文本中。

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

\begin{document}

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

\LipsumPar{1}

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

\LipsumPar{2}
\LipsumPar{3}

\end{document}

相关内容