打印多项选择题的答案

打印多项选择题的答案

我正在使用exam文档类,我想打印正确答案的字母。例如:

\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}

    The answer is /theCorrectChoice

\end{questions}

\end{document}

我在网上看到过类似的问题,但我找不到一个好方法来直接引用“正确的选择”,例如引用/问题。有人知道如何解决这个问题吗?

答案1

您可以更新\CorrectChoice以插入增量\label。但是,这意味着只有最新的\CorrectChoice才会通过调用返回\theCorrectChoice

在此处输入图片描述

\documentclass{exam}% http://ctan.org/pkg/exam

\newcounter{correctchoicemark}% Counter to keep track of correct choice mark
\newcommand{\theCorrectChoice}{\ref{correctchoice-\thecorrectchoicemark}}% Print correct choice
\renewcommand{\choiceshook}{% Adapt \CorrectChoice to insert \label
  \let\oldCorrectChoice\CorrectChoice% Store \CorrectChoice in \oldCorrectChoice
  \renewcommand{\CorrectChoice}{%
    \oldCorrectChoice% Original \CorrectChoice
    \stepcounter{correctchoicemark}% Increment correct choice mark
    \label{correctchoice-\thecorrectchoicemark}% \label original \CorrectChoice
  }%
}
\let\oldoneparchoices\oneparchoices
\renewcommand{\oneparchoices}{%
  \oldoneparchoices% Original oneparchoices environment start
  \let\oldCorrectChoice\CorrectChoice% Store \CorrectChoice in \oldCorrectChoice
  \renewcommand{\CorrectChoice}{%
    \oldCorrectChoice% Original \CorrectChoice
    \stepcounter{correctchoicemark}% Increment correct choice mark
    \label{correctchoice-\thecorrectchoicemark}% \label original \CorrectChoice
  }%
}
\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}

  The answer is \theCorrectChoice.

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

  The answer is \theCorrectChoice.

\end{questions}

\end{document}

examchoices通过提供了一个环境挂钩\choiceshook。将其更新为重新定义\CorrectChoice是插入适当代码以获得\label您可以获得的\ref结果的一种(干净)方法。oneparchoices不提供此挂钩,因此采用完全不同的方法来重新定义\CorrectChoice

要使此解决方案正常工作,还需要做更多工作hyperref

相关内容