Jérôme Belleman
Home  •  Tools  •  Posts  •  Talks  •  Travels  •  Graphics  •  About Me

Ways to Having Text Wrap Pictures with LaTeX

14 Oct 2004

While it is more common to use floats with LaTeX, it is possible to place a picture – or anything else, in fact – next to text that will elegantly wrap it up.

1 With the picinpar Package

The picinpar package provides environments to open windows inside paragraphs. For instance, consider the following code:

\documentclass{article}
\usepackage{picinpar}

\begin{document}

\begin{window}[3,c,\fbox{This is the window},]
    Lorem ipsum dolor sit amet, consectetur adipiscing elit. Pellentesque
    commodo id augue non ornare. Suspendisse egestas orci sit amet consectetur
    porttitor. Aliquam sed congue neque. Cras luctus tortor in augue ornare,
    ac blandit est malesuada. Ut pretium aliquam diam, vitae molestie ipsum
    ultricies vitae. Integer ac ex bibendum, dapibus justo ut, consequat
    dolor. Donec egestas diam vitae dictum consectetur. Integer sagittis
    purus eget arcu pharetra varius. Sed euismod turpis urna, non auctor urna
    porta sit amet. Maecenas congue purus nec ullamcorper tempus. Praesent
    egestas ligula metus, ac laoreet sem convallis id. Pellentesque eget
    nulla volutpat, fermentum augue ac, tincidunt est. Donec sed dui id nisi
    gravida molestie quis eu augue.
\end{window}

\end{document}

It will result to this paragraph:

A Window into a Paragraph of Text
A Window into a Paragraph of Text

Crucially, the first argument in the no-so-optional option is the number of lines into the paragraph where the window needs opening. The second argument is the alignment, and it's not a stretch to guess that turning c to r is enough to make it look a proper wrapping. The third argument is the contents of the window. The trailing comma isn't a typo, but introduces the fourth argument which is the caption and which I'm not using and therefore left empty.

The LATEX Companion, § 3.1.6 picinpar – Typeset a Paragraph with a Rectangular Hole, p. 53 describes this package in more details.

2 With the wrapfig Package

The wrapfig package is used as follows:

\begin{wrapfigure}[nlines][overhang]{placement}{width}

The placement parameter can be l or r and overhang is the margin overhang length. For instance:

\begin{wrapfigure}{r}{100pt}
 \includegraphics[width=100pt]{foo.png}
\end{wrapfigure}
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Pellentesque commodo
id augue non ornare. Suspendisse egestas orci sit amet consectetur porttitor.

The LATEX Companion, § 6.4.2 wrapfig – Wrapping Text around a Figure, p. 151 describes this package in more details.

3 With the picins Package

The picins package is not to be confused with the picinpar package previously discussed. It's used as follows:

\parpic(w,h)(x-o,y-o)[opt][pos]{pict}

Note that (x,y) is optional. The (x-o,y-o) parameters are also optional and describe an offset from a top-left origin. The opt parameter is a pair of one positional (l or r) and one frame (dash, frame, oval, shadow or box) specifier. The pos parameter indicates the position of the picture inside its frame, made of a horizontal (l or r) and/or vertical (t or b) alignment; this option is ignored if (x-o,y-o) is specified.

\parpic{\includegraphics[width=100pt]{foo.png}}
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Pellentesque commodo
id augue non ornare. Suspendisse egestas orci sit amet consectetur porttitor.

Several parameters can be tuned to get the right effect: \picskip(n}, called after \parpic, has the picture place holder be as long as n lines; the \pichskip command comes before the \parpic call and is passed a horizontal length to the text; the \linethickness, \dashlength, \shadowthickness and \boxlength commands are passed lengths and come before the \parpic call. Captions can be used by calling \piccaption{my caption} before \parpic. Their positions can be adjusted with the \piccaptionoutside (default), \piccaptioninside, \piccaptionside and \piccaptiontopside commands called before \parpic; these positions are relative to the frame.

4 Interactions Between List Environments, wrapfig and picins

I found that neither picins nor wrapfig played very well with itemize and enumerate environments and that you might as well get away with it using minipages:

\item \begin{minipage}[t]{.8\linewidth}
        Lorem ipsum dolor sit amet, consectetur adipiscing elit. Pellentesque
        commodo id augue non ornare. Suspendisse egestas orci sit amet
        consectetur porttitor.
      \end{minipage}%
      \begin{minipage}[t]{.2\linewidth}
        \vspace{-\baselineskip}
        \includegraphics[width=.9\textwidth]{foo.png}
      \end{minipage}

You want to align-top it all and comment out the newline between the two minipages, obviously. What's not so obvious however it that you also need to place images by a negative \vspace of \baselineskip length to prevent them from sticking up.

5 References