One of the drawbacks to using wrapfig
in LaTeX is that it doesn’t behave well in enumerated or list environments. Usually what happens is that wrapfig
doesn’t know how to wrap around /begin
and /end
statements, so it drops the figure down to the bottom.
Here’s the quickest workaround I’ve been able to find.
In my example, I’m using the exam document class
, in it there is an enumerated list called questions, within each question, there is a subsection called parts. What I want to do is to insert a figure into each question, and have it wrap around the question on the right-hand side.
This would be my structure without the figures inserted:
\documentclass[letterpaper]{exam} \begin{questions} \question This is question 1. \begin{parts} \part This is part a. \part This is part b. \end{parts} \question This is question 2. \begin{parts} \part This is part a. \part This is part b. \end{parts} \end{questions} \end{document}
Now I will insert 2 figures, wrapped using wrapfig. But to make it work, I will have to enclose the question and the figure in a minipage (changes are in blue):
\documentclass[letterpaper]{exam} \usepackage[pdftex]{graphicx} \usepackage{wrapfig} \begin{questions} \begin{minipage}{\linewidth} \begin{wrapfigure}{r}{1.5in} \vspace{-12pt} \includegraphics[width=1.5in]{figure.png} \end{wrapfigure} \question This is question 1. \begin{parts} \part This is part a. \part This is part b. \end{parts} \end{minipage} \begin{minipage}{\linewidth} \begin{wrapfigure}{r}{1.5in} \vspace{-12pt} \includegraphics[width=1.5in]{figure.png} \end{wrapfigure} \question This is question 2. \begin{parts} \part This is part a. \part This is part b. \end{parts}\end{minipage} \end{questions} \end{document}
The \vspace{-12pt}
just lines up the top of the figure to the first line. You can omit it if you’d like. Otherwise, this is a very simple, though tedious, way of making sure you can insert and wrap figures in enumerated and list environments in LaTeX. The end result looks like the following (note that these are dummy blue png files in the example for now):