# Wrap text between figures on both left and right

Naively enough, I had expected that two wrapfigure environments, one left-aligned and the other right-aligned, would not interfere with one another, and that text would simply flow (i.e., wrap) in between them. However, this does not appear to be the case.

For (minimal working) example, this code:

\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}


Produces this:

But I was after something like this:

I managed to kludge together the above using some minipage environments, but this is not as helpful for my purpose, since it forces me to predetermine the specific text that will end up between the images, whereas of course what I'm looking for is a fluid and automatic "wrap" such as one gets with wrapfigure but in between the two images, as opposed to around just one.

Is there a way to use the wrapfigure environment for this purpose? If not, then what could I use instead?

• Doing both sides is a complication wrapfigure doesn't need. The tricky bit is being able to handle multiple paragraphs. In you case, however, you have a single paragraph. – John Kormylo Oct 17 '18 at 23:13
• – A.Ellett Oct 18 '18 at 3:56

This solution creates macro \WrapLR which (like wrapfig) uses \parshape. The top of the image is \ht\strutbox above the first baseline, and the bottom is even or higher than the last baseline (assuming normal line spacing). It can even handle images of different heights.

\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
\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}