I can wrap in ARTICLE, but not in EXAM. How to wrap in EXAM?
(Question Plus-if you´re a LaTeX master-.- What´s the mosr suitable and easy package to do this kind of things?)
I can wrap a figure in an ARTICLE document
with this code
\documentclass[12pt]{article}
\usepackage{graphicx,wrapfig,lipsum}
\usepackage[onehalfspacing]{setspace}
\usepackage{mwe}
\begin{document}
%\begin{questions}
\begin{wrapfigure}{r}{.3\linewidth}
\centering
\includegraphics[width=\linewidth]{example-image-a.png}
\caption{This is A}
\end{wrapfigure}
Hello, I want to wrap this figure in exam
\lipsum[2]\lipsum[1]
%\end{questions}
\end{document}
BUT I´d like wrap images in EXAM documents, and this code doesn´t give the wrapped figure:
\documentclass[12pt]{exam}
\usepackage{graphicx,wrapfig,lipsum}
\usepackage[onehalfspacing]{setspace}
\usepackage{mwe}
\begin{document}
\begin{questions}
\begin{wrapfigure}{r}{.3\linewidth}
\centering
\includegraphics[width=\linewidth]{example-image-a.png}
\caption{This is A}
\end{wrapfigure}
\question Hello, I want to wrap this figure in exam
\lipsum[2]\lipsum[1]
\end{questions}
\end{document}
**
EDITED (2019/02/24) Afther trying Skillmon solution, I have a new problem with lists(enumerate) in the questions
**
With the code (only adding itemize in thq euestion with the figure)
\documentclass[12pt]{exam}
\usepackage{graphicx,wrapfig,lipsum}
\input{insbox}
\usepackage{capt-of}
\usepackage[onehalfspacing]{setspace}
\usepackage{mwe}
\usepackage{etoolbox}
\makeatletter
%% Stealing some code from exam:
\def\mypointshandling
{%>>>
\if@bonus
\def\padded@point@block{%
\begingroup
\@placepointstrue
\bonuspoint@block
\endgroup
}%
\else
\def\padded@point@block{%
\begingroup
\@placepointstrue
\point@block
\endgroup
}%
\fi
\if@pointsdropped
\else
\if@bonus
\if@bonusqformat
\ifx\ques@ref\@queslevel
\else
\setup@point@toks
\fi
\else
\setup@point@toks
\fi
\else
\if@qformat
\ifx\ques@ref\@queslevel
\else
\setup@point@toks
\fi
\else
\setup@point@toks
\fi
\fi
\fi
\global \MyIfPointsfalse
}%<<<
\newif\ifMyIfPoints
\protected\def\questionInsbox
{%
\@ifnextchar[\questionInsbox@a{\questionInsbox@a[]}%
}
\protected\long\def\questionInsbox@a[#1]#2#3%
{%
\@ifnextchar[{\questionInsbox@b{#1}{#2}{#3}}
{\questionInsbox@b{#1}{#2}{#3}[0]}
}
\long\def\questionInsbox@b#1#2#3[#4]%
{%
\apptocmd\@itemlabel{\hskip\leftmargin}{}{}%
\def\makelabel##1{\hss\llap{##1}}%
\if\relax\detokenize{#1}\relax
\question
\else
\global\MyIfPointstrue
\patchcmd\@readpoints{\global\@placepointstrue}{\relax}{}{}%
\question[#1]%
\patchcmd\@readpoints{\relax}{\global\@placepointstrue}{}{}%
\fi
\patchcmd\@itemlabel{\hskip\leftmargin}{}{}{}%
\let\makelabel\@mklab
\mbox{}%
\vspace*{-\baselineskip}%
\setlength{\leftskip}{\leftmargin}%
\InsertBoxR{#2}{\hskip-\leftmargin#3\hskip\leftmargin}[#4]%
\ifMyIfPoints
\mypointshandling
\fi
\the\point@toks
\ignorespaces
}
\makeatother
\begin{document}
\begin{questions}
\question Jei you
\questionInsbox[5]{0}
{%
\parbox[t]{.3\linewidth}
{%
\centering
\includegraphics[width=\linewidth]{example-image-a.png}
\captionof{figure}{This is A}%
}%
}[1]
Hello, I want to wrap this figure in exam, and you should choose the rigth answer:
\begin{enumerate}
\item \lipsum[1]
\item \lipsum[1]
\end{enumerate}
\question Another
\end{questions}
\end{document}
The solution, not the best but… on the fly I have typed is:
\question See figure and answer, please:
\begin{enumerate}
\begin{multicols}{2}
\item answer 1
\item ans 2
\item ans 3
{\centering
\begingroup
\centering
\includegraphics[width=1.00\linewidth]{{example-image-a.png}
\vspace{-0.3cm}
\captionof{figure}{}
\label{fig:croquis-rectangulo-ecuacions.png}
\endgroup}
\end{multicols}
\item ans afeter fig
\end{enumerate}
EDIT (2019/02/25) after EDIT 3 of Skillmon
I admire yout knowledge of LaTeX programming. It´s fantastic!!
The solution if perfect for normal text but when you use lists (enumerate, itemize,…) the problem is remaining.
After reading the last comments (2019/02/24) of Skillmon, I decide to simulate the lists in normal text. With
\
a) answer 1 answer 1 answer 1 answer 1 answer 1 answer 1 answer 1 answer 1 answer 1 answer 1 answer 1 answer 1\
b) answer 2 answer 2 answer 2 answer 2 answer 2 answer 2 answer 2 answer 2 answer 2 answer 2 answer 2 answer 2\
LaTeX is so beatifull, so complicated!!
Waiting for this option (I´m optimistic, yes!! 🙂 ) in exam class in the future… I´ll use your solutions sometimes.
Only fails in the bottom of page, as far as I can see, and when you use some \questionInsboxL[5]{2} with close to blank page between questions.
THANK YOU FOR ALL YOUR SOLUTIONS AND EFFORTS!
THANK YOU, SKILLMON
Best Answer
wrapfig
doesn't work in lists, andquestions
is just another version of a list. The following is a quick and dirty reimplementation of https://tex.stackexchange.com/a/453624/117050 to work withenumerate
like lists instead of withitemize
. It usesinsbox
just like @Bernard's answer, but shouldn't require a manual paragraph. It does only implement the code to wrap inside one question, not inside the next one, too.EDIT: It now should support
exam
's points system, but I didn't test it thoroughly. You might come back and complain if it doesn't work out.EDIT2: Streamlined the interface to be more like the one of
\InsertBoxR
, the new macro's name is\questionInsboxR
and it takes an optional argument, two mandatory ones, and a second optional one. The first optional argument is like the one of\question
, the two mandatory arguments and the following optional one are like those of\InsertBoxR
.EDIT3: Added
\questionInsboxL
, fixed behaviour of multiple\questionInsboxL/R
usages inside onequestions
environment.