我正在使用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}
exam
choices
通过提供了一个环境挂钩\choiceshook
。将其更新为重新定义\CorrectChoice
是插入适当代码以获得\label
您可以获得的\ref
结果的一种(干净)方法。oneparchoices
不提供此挂钩,因此采用完全不同的方法来重新定义\CorrectChoice
。
要使此解决方案正常工作,还需要做更多工作hyperref
。