# Multiple choice question with figure choices gives error when used with \printanswers command in exam class

This question has been modified from this question with added feature. However, when I used \printanswers command, the code gives an error the following error:

! Extra }, or forgotten \endgroup.
\endmulticols ->\par \if@boxedmulticols \egroup
\balance@columns \return@non...
l.24             \end{multicols}

?


My MWE code modified with suggestion from Gonzalo Medina when used with \noprintanswers is given below:

\documentclass{exam}
\usepackage{multicol}
\usepackage{graphicx}
\begin{document}
\begin{questions}
\question
\begin{minipage}[t]{0.65\linewidth}
Consider the network graph shown in the figure, which of the following is NOT a \textit{tree} of this graph?
\begin{choices}
\begin{multicols}{2}
\choice
\choice
\end{multicols}\par
\begin{multicols}{2}
\choice
\CorrectChoice
\end{multicols}
\end{choices}
\end{minipage}\hfill%
\includegraphics[width=\linewidth]{example-image-a}
\end{questions}
\end{document}


When \printanswers command is used, it should give the output like this highlighting the partlabel corresponding to the \CorrectChoice:

Any suggestion to solve the error when used \printanswer command in the given code!

• Ther other answer to your previous question works in this case too. Is there any reason you don't want to use it? – user11232 Oct 11 '15 at 2:55
• Have you tried @HarishKumar's answer? In your comment on the other answer to your other question, you don't make this clear. Presumably you'd at least get a different error in that case? – cfr Oct 11 '15 at 2:57
• I will see to it Harish. I wanted minimum changes to the original code and found convenient to use with what Gonzalo has suggested. It proved good and working as long as I use \noprintanswers command to the code. But it results an error when I put \printanswers command. – Khaaba Oct 11 '15 at 2:59
• This happen only if \CorrectChoice is last. In this case you can try with\CorrectChoice\endgroup. – touhami Oct 11 '15 at 5:58

Updated In this solution, we define new environment multichoices that works like multicols, by defaut it hase two columns but one can set more if needed.

\makeatletter
\newenvironment{multichoices}[1][2]{%
\begin{multicols}{#1}}{%
\if@correctchoice \endgroup \fi
\end{multicols}}
\makeatother


MWE

\documentclass{exam}
\usepackage{multicol}
\usepackage{graphicx}

\makeatletter
\newenvironment{multichoices}[1][2]{%
\begin{multicols}{#1}}{%
\if@correctchoice \endgroup \fi
\end{multicols}}
\makeatother

\begin{document}
\begin{questions}
\question
\begin{minipage}[t]{0.65\linewidth}
Consider the network graph shown in the figure, which of the following is NOT a \textit{tree} of this graph?
\begin{choices}
\begin{multichoices}
\choice
\choice
\end{multichoices}\par
\begin{multichoices}
\CorrectChoice
\choice
\end{multichoices}
\end{choices}
\end{minipage}\hfill%
\includegraphics[width=\linewidth]{example-image-a}

\question
\begin{minipage}[t]{0.65\linewidth}
Consider the network graph shown in the figure, which of the following is NOT a \textit{tree} of this graph?
\begin{choices}
\begin{multichoices}
\choice
\choice
\end{multichoices}\par
\begin{multichoices}
\choice
\CorrectChoice
\end{multichoices}
\end{choices}
\end{minipage}\hfill%
\includegraphics[width=\linewidth]{example-image-a}

\question
\begin{minipage}[t]{0.65\linewidth}
Consider the network graph shown in the figure, which of the following is NOT a \textit{tree} of this graph?
\begin{choices}
\begin{multichoices}
\choice
bla bla
\choice
bla bla
\end{multichoices}\par
\begin{multichoices}
\choice
bla bla
\CorrectChoice
bla bla
\end{multichoices}
\end{choices}
\end{minipage}\hfill%
\includegraphics[width=\linewidth]{example-image-a}

\question
\begin{minipage}[t]{0.65\linewidth}
Consider the network graph shown in the figure, which of the following is NOT a \textit{tree} of this graph?
\begin{choices}
\begin{multichoices}
\choice
bla bla
\choice
bla bla
\end{multichoices}\par
\begin{multichoices}
\CorrectChoice
bla bla
\choice
bla bla
\end{multichoices}
\end{choices}
\end{minipage}\hfill%

• it worked without the aforementioned error in the original question with tikzpicture environment instead of includegraphics. Now after the recent update, I have started getting the aforementioned error with tikzpicture: ! Extra }, or forgotten \endgroup. I can't get a clue to fix it. Could you please help me? – Khaaba Sep 25 '18 at 16:05