3

I am writing multiple choice paper in following format

\documentclass{exam}

\begin{document}

\begin{questions}

\question This is a multiple choice question
\begin{choices}
   \choice this is a choice
   \choice this is another choice
   \CorrectChoice this is the correct choice
   \choice this is another choice
\end{choices}

\end{questions}

\end{document}

and I want keys to display at the end of document in table but couldn't get. Kindly help.

2 Answers 2

6

I didn't find any way to do this in the manual for the exam class, so I made a quick custom solution that prints a list of answers automatically. The only thing that you must do is to use \CC for the correct choice, and then write \printmyanswers to display the answers as a list. There are some examples on this site for the tabular, but it's pretty verbose and I'm not sure it's worth it.

I put the answers in the same page, but you can simply add a \newpage before the command, for example.

Output

enter image description here

Code

\documentclass{exam}
\usepackage{pgffor}

\newcounter{solcount}
\setcounter{solcount}{1}
\newcommand\CC{%
    \CorrectChoice\label{sol:\arabic{solcount}}
    \stepcounter{solcount}
}

\newcommand\printmyanswers{%
\section*{\centering Answers Sheet}
    \foreach \x in {1,...,\thequestion}{%
    \noindent
        \x.~\ref{sol:\x}\par
    }
}

\begin{document}\noindent
\begin{questions}

\question This is a multiple choice question
\begin{choices}
   \choice this is a choice
   \choice this is another choice
   \CC this is the correct choice
   \choice this is another choice
\end{choices}

\question This is a multiple choice question
\begin{choices}
   \choice this is a choice
   \CC this is the correct choice
   \choice this is another choice
   \choice this is another choice
\end{choices}
\end{questions}

\printmyanswers
\end{document}
6
  • The problem with this code is that the \CC options appears in a more darker font color, hence students will easily tell that it's the intended answer
    – Freeman
    Apr 23, 2017 at 8:24
  • @Freeman Did you verify this by printing the page? PDF viewers are not 100% reliable as they create artefacts at times. Also, the font I used is black, so what you say is highly unlikely to say the least as there is no darker color than black.
    – Alenanno
    Apr 23, 2017 at 10:22
  • i will print it later on, however the other challenge i am encountering is that it only prints four answers. However i really like the code as i do not need to manually write answers. It is really really good, except for those two
    – Freeman
    Apr 23, 2017 at 10:38
  • @Freeman Sorry, not sure I understand. Are you referring to the multiple choice answers? Or the solutions? I'm asking so I can test your situation.
    – Alenanno
    Apr 23, 2017 at 13:43
  • The solutions. I only managed to compile only four solutions, with 13 questions.
    – Freeman
    Apr 24, 2017 at 3:30
1

To remove bold correct choices

\CorrectChoiceEmphasis{}

Before

After

To remove the bolded answer when printing the answer key. More information can be found here here: http://mirrors.ctan.org/macros/latex/contrib/exam/examdoc.pdf

Table Answer Key

\usepackage{xintexpr}
\usepackage[table]{xcolor}    % loads also »colortbl«
\usepackage{color, colortbl}
\usepackage{pgffor}


\newcommand\CC{%
  \CorrectChoice\label{sol:\thequestion}
}

\newcommand{\AnswerKeyCols}{10}
\newcommand{\AnswerKeyRows}{\xinttheexpr ceil(\thequestion / \AnswerKeyCols)\relax}

\newcommand\printmyanswers{%
\section*{\centering Answers Sheet}
  \edef\rowSeq {\xintSeq{0}{\AnswerKeyRows-1}}
  \edef\colSeq {\xintSeq{1}{\AnswerKeyCols}}

  \begin{center}
  \begin{tabular}{|*{\AnswerKeyCols}{c|}}
  \hline
  \xintFor* ##1 in {\rowSeq} \do {%
  \xintFor* ##2 in {\colSeq} \do {\xintifForFirst{}{&}\cellcolor{gray}##2}\\
  \hline
  \xintFor* ##3 in {\colSeq} \do {\xintifForFirst{}{&}\xintifboolexpr{##1*\AnswerKeyCols + ##3 <= \thequestion}{~\ref{sol:##3}}{}}\\
  \hline
  }
  \end{tabular}
  \end{center}
}


Table Answer Key

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .