我天真地以为,两个wrapfigure
环境(一个左对齐,另一个右对齐)不会互相干扰,文本会在它们之间流动(即换行)。然而,事实似乎并非如此。
对于(最小工作)示例,此代码:
\documentclass{article}
\usepackage{wrapfig}
\usepackage{graphicx}
\usepackage{fullpage}
\begin{document}
\begin{wrapfigure}[10]{l}{0.175\textwidth}
\includegraphics[height=1.2in]{Caratheodory1.jpg}
\end{wrapfigure}
Constantin began his formal schooling at a private school in Vanderstock in 1881. He left after two years and then spent time with his father on a visit to Berlin, and also spent the winters of 1883--84 and 1884--85 on the Italian Riviera. Back in Brussels in 1885 he attended a grammar school for a year where he first began to become interested in mathematics. In 1886, he entered the high school Ath\'en\'ee Royal d'Ixelles and studied there until his graduation in 1891. Twice during his time at this school Constantin won a prize as the best mathematics student in Belgium. Constantin Caratheodory (left) pictured sitting with his father, brother in law and sister, Carlsbad 1898
\begin{wrapfigure}[10]{r}{0.175\textwidth}
\includegraphics[height=1.2in]{Caratheodory2.jpg}
\end{wrapfigure}
\end{document}
产生这个:
但我追求的是这样的:
我设法使用一些minipage
环境将上述内容拼凑在一起,但这对我的目的没有太大帮助,因为它迫使我预先确定最终出现在图像之间的特定文本,而我当然想要的是流畅而自动的“包装”,比如一个人得到的,wrapfigure
但在两个图像之间,而不是只围绕一个。
有没有办法将wrapfigure
环境用于此目的?如果没有,那么我可以用什么来代替?
答案1
此解决方案创建\WrapLR
使用 的宏(如 wrapfig)\parshape
。图像的顶部位于\ht\strutbox
第一条基线上方,底部与最后一条基线齐平或更高(假设行距正常)。它甚至可以处理不同高度的图像。
\documentclass{article}
\usepackage{graphicx}
\usepackage{fullpage}% ???
\newcommand*{\WrapLR}[3]% #1=left image, #2=right image, #3=text (1 paragraph)
{\bgroup
\sbox0{\raisebox{-\height}{#1}}% align tops
\sbox1{\raisebox{-\height}{#2}}% measure width and height (depth)
\sbox2{\raisebox{\depth}{\makebox[\textwidth]{\usebox0\hfill\usebox1}}}% total height
\par\noindent\usebox2\vspace{\dimexpr \ht\strutbox-\ht2-\baselineskip-\parskip}\par% overlay pictures
\dimen0=\dimexpr \wd0+\columnsep\relax% indent
\dimen1=\dimexpr \textwidth-\wd0-\wd1-2\columnsep\relax% width
\edef\shape{\the\dimen0 \the\dimen1}% set up \parshape arguments in loop
\dimen2=\ht\strutbox
\count1=2
\loop\ifdim\dimen2<\ht2
\ifdim\dimen2>\dp0\relax% end of left image
\dimen0=0pt
\dimen1=\dimexpr \textwidth-\wd1-\columnsep\relax
\fi
\ifdim\dimen2>\dp1\relax% end of right image
\dimen1=\dimexpr \textwidth-\wd0-\columnsep\relax
\fi
\advance\dimen2 by \baselineskip
\advance\count1 by 1
\edef\shape{\shape\space\the\dimen0 \the\dimen1}%
\repeat
\edef\shape{\the\count1 \space\shape\space 0pt \the\textwidth}%
\parshape=\shape
#3\par
\egroup}
\begin{document}
\WrapLR{\includegraphics[height=1.2in]{example-image-a}}%
{\includegraphics[height=1.2in]{example-image-b}}%
{\noindent Constantin began his formal schooling at a private school in Vanderstock in 1881. He left after two years and then spent time with his father on a visit to Berlin, and also spent the winters of 1883--84 and 1884--85 on the Italian Riviera. Back in Brussels in 1885 he attended a grammar school for a year where he first began to become interested in mathematics. In 1886, he entered the high school Ath\'en\'ee Royal d'Ixelles and studied there until his graduation in 1891. Twice during his time at this school Constantin won a prize as the best mathematics student in Belgium. Constantin Caratheodory (left) pictured sitting with his father, brother in law and sister, Carlsbad 1898}
\end{document}