[Tex/LaTex] wrapfigure within an exam

examwrapfigure

I am trying to float a figure using wrapfigure within an exam document using minipage. If I don't use a minipage, then the exam questions do not wrap around the figure. When I use minipage as in the example below, everything wraps, but if the minipage (or the longer form with solutions included with \printanswers) is longer than one page, then the typesetting runs off the bottom.

My simple question is this: what's the correct way to include figures in an exam? My example questions block follows:

\documentclass{exam}
\usepackage{amsmath}
\usepackage{graphics}
\usepackage{wrapfig}
\begin{document}
\begin{questions}
\begin{minipage}{\linewidth}
\begin{wrapfigure}{r}{9cm}
\includegraphics[width=8cm]{./20x20grid-axes.png}
\end{wrapfigure}

\question Answer all parts below: 

\begin{parts}

\part[1] 1 + 1 = \answerline

\fullwidth{\begin{solution}\begin{align*} \boxed{ 2 } \end{align*}\end{solution}}

\part[1] 2 + 2 = \answerline

\fullwidth{\begin{solution}\begin{align*} \boxed{ 4 } \end{align*}\end{solution}}

\part[1] 3 + 3 = \answerline

\fullwidth{\begin{solution}\begin{align*} \boxed{ 6 } \end{align*}\end{solution}}

\end{parts}
\end{minipage}
\end{questions}
\end{document}

Best Answer

One possibility would be to move the minipage inside the parts environment, and ending it as soon as enough material has been wrapped, as the following example illustrates:

\documentclass{exam}
\usepackage[demo]{graphicx}
\usepackage{wrapfig}
\usepackage{amsmath}

\begin{document}

\begin{questions}
\question Answer all parts below: 

\begin{parts}
\begin{minipage}{\linewidth} 
\begin{wrapfigure}{r}{9cm}
\hfill
\includegraphics[width=8cm]{./20x20grid-axes.png}
\end{wrapfigure}
\part[1] 1 + 1 = \answerline

\fullwidth{\begin{solution}\begin{align*} \boxed{ 2 } \end{align*}\end{solution}}

\part[1] 2 + 2 = \answerline

\fullwidth{\begin{solution}\begin{align*} \boxed{ 4 } \end{align*}\end{solution}}

\part[1] 3 + 3 = \answerline

\fullwidth{\begin{solution}\begin{align*} \boxed{ 4 } \end{align*}\end{solution}}
\end{minipage}

\part[1] 3 + 6 = \answerline

\fullwidth{\begin{solution}\begin{align*} \boxed{ 6 } \end{align*}\end{solution}}

\end{parts}
\end{questions}

\end{document}

enter image description here

The demo option for graphicx simply replaces actual figures with black rectangles; do not use that option in your actual document.

Related Question