1

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}
\usepackage{adjustbox}
%\printanswers
\noprintanswers
\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
                    \adjustbox{valign=t}{\includegraphics[scale=0.2]{example-image-a}}
                \choice
                    \adjustbox{valign=t}{\includegraphics[scale=0.2]{example-image-b}}
        \end{multicols}\par
        \begin{multicols}{2}
                \choice
                    \adjustbox{valign=t}{\includegraphics[scale=0.2]{example-image-c}}
                \CorrectChoice
                    \adjustbox{valign=t}{\includegraphics[scale=0.2]{example-image-a}}
        \end{multicols}
            \end{choices}
\end{minipage}\hfill%
    \begin{adjustbox}{minipage={0.30\linewidth},valign=t}
    \includegraphics[width=\linewidth]{example-image-a} 
\end{adjustbox}
\end{questions}
\end{document}

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

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

cfr
  • 198,882
Khaaba
  • 1,848
  • 1
  • 22
  • 34
  • 1
    Ther other answer to your previous question works in this case too. Is there any reason you don't want to use it? –  Oct 11 '15 at 02: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 02: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 02:59
  • This happen only if \CorrectChoice is last. In this case you can try with\CorrectChoice\endgroup. – touhami Oct 11 '15 at 05:58

1 Answers1

1

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}
\usepackage{adjustbox}
\printanswers
%\noprintanswers

\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
                    \adjustbox{valign=t}{\includegraphics[scale=0.2]{example-image-a}}
                \choice
                    \adjustbox{valign=t}{\includegraphics[scale=0.2]{example-image-b}}
        \end{multichoices}\par
        \begin{multichoices}
                \CorrectChoice
                    \adjustbox{valign=t}{\includegraphics[scale=0.2]{example-image-a}}
                \choice
                    \adjustbox{valign=t}{\includegraphics[scale=0.2]{example-image-c}}
        \end{multichoices}
            \end{choices}
\end{minipage}\hfill%
    \begin{adjustbox}{minipage={0.30\linewidth},valign=t}
    \includegraphics[width=\linewidth]{example-image-a} 
\end{adjustbox}


    \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
                    \adjustbox{valign=t}{\includegraphics[scale=0.2]{example-image-a}}
                \choice
                    \adjustbox{valign=t}{\includegraphics[scale=0.2]{example-image-b}}
        \end{multichoices}\par
        \begin{multichoices}
                \choice
                    \adjustbox{valign=t}{\includegraphics[scale=0.2]{example-image-c}}
                \CorrectChoice
                    \adjustbox{valign=t}{\includegraphics[scale=0.2]{example-image-a}}
        \end{multichoices}
            \end{choices}
\end{minipage}\hfill%
    \begin{adjustbox}{minipage={0.30\linewidth},valign=t}
    \includegraphics[width=\linewidth]{example-image-a} 
\end{adjustbox}

    \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%
    \begin{adjustbox}{minipage={0.30\linewidth},valign=t}
    \includegraphics[width=\linewidth]{example-image-a} 
\end{adjustbox}


    \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%
    \begin{adjustbox}{minipage={0.30\linewidth},valign=t}
    \includegraphics[width=\linewidth]{example-image-a} 
\end{adjustbox}

\end{questions}
\end{document}

enter image description here enter image description here

touhami
  • 19,520
  • Touhami, can you please add another question in which choices are texts only along with this figure choices? Code runs but correctchoice label is missing when I use \printanswers command? May be I need little more understanding of the tricks you have provided. – Khaaba Oct 11 '15 at 07:50
  • you're right I can't see it now, I will try later. – touhami Oct 11 '15 at 08:11
  • 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
  • @Khaaba please ask a new question. – touhami Sep 25 '18 at 19:46
  • thank you for the reply. I have put the question here – Khaaba Sep 26 '18 at 02:57