1

I am having a problem in using multicols environment in exercise environment. Here is my MWE:

\documentclass[11pt]{exam}

\usepackage{amsfonts} \usepackage{amssymb} \usepackage{amsmath} \usepackage{multicol} \usepackage{ifthen} \newboolean{firstanswerofthechapter}
\usepackage{stackengine} \usepackage{tasks} \newlength{\longestlabel} \settowidth{\longestlabel}{\bfseries\sffamily vv} \settasks{after-item-skip=3pt,%gap for next row before-skip=2pt,%gap from the text above
after-skip=0pt,%gap for next question label-width=20pt,%width from left item-indent=25pt,%indent from left label=$\EgyptianBlue\bm{(\alph*)}$, column-sep=0em, label-align=left}

\usepackage[lastexercise,answerdelayed]{exercise}

\begin{document}

\setcounter{Exercise}{0}

\begin{Exercise}

\Question \Question \Question

\end{Exercise}

\begin{Answer}

\Question $(a)$

\begin{multicols}{4} \Question $(a)$ \Question $(a)$ \Question $(a)$ \Question $(a)$ \end{multicols}

\end{Answer} \setboolean{firstanswerofthechapter}{false} \shipoutAnswer

\end{document}

There is no problem in the code if I start Answer environment with a \Question, however, if I start with \multicols environment (without any \Question before \multicols), then I get the following error:

Extra }, or forgotten \endgroup.
\endmulticols ...le@items \color@endgroup \egroup 
                                                  \balance@columns \return@n...
l.60 \end{multicols}

I need to start Answer environment with \multicols. I also want the answers to be typed from left to right like

   1.     2.      3.       4.
   5.     6.      7.       8.

Please help.

Deepak
  • 11

1 Answers1

1

This problem is discussed in section "4 Known problems" of the exercise documentation. You can avoid the error by adding \EndCurrentQuestion before the multicols environment ends:

\documentclass[11pt]{exam}

\usepackage{amsfonts} \usepackage{amssymb} \usepackage{amsmath} \usepackage{multicol} \usepackage{ifthen} \newboolean{firstanswerofthechapter}
\usepackage{stackengine} \usepackage{tasks} \newlength{\longestlabel} \settowidth{\longestlabel}{\bfseries\sffamily vv} \settasks{after-item-skip=3pt,%gap for next row before-skip=2pt,%gap from the text above
after-skip=0pt,%gap for next question label-width=20pt,%width from left item-indent=25pt,%indent from left label=$\EgyptianBlue\bm{(\alph*)}$, column-sep=0em, label-align=left}

\usepackage[lastexercise,answerdelayed]{exercise}

\begin{document}

\setcounter{Exercise}{0}

\begin{Exercise}

\Question \Question \Question

\end{Exercise}

\begin{Answer}

\begin{multicols}{4} \Question $(a)$ \Question $(a)$ \Question $(a)$ \Question $(a)$ \EndCurrentQuestion \end{multicols}

\end{Answer} \setboolean{firstanswerofthechapter}{false} \shipoutAnswer

\end{document}

  • Thanks Samcarter. Your solution works but now I am having different problem. I need to add the command \EndCurrentQuestion in every set of four answers. Also, the answer number again starts with 1. – Deepak Jan 04 '24 at 16:41
  • If I use a single \multicols environment, then the answers are typed vertically, but I need them to be horizontal. – Deepak Jan 04 '24 at 16:49
  • @Deepak If you have a new question, please ask a new question. – samcarter_is_at_topanswers.xyz Jan 05 '24 at 09:49