我认为这是一个后续问题:
我试图在课程文档末尾创建一个答案,exam
其中所有问题都是多项选择题。因此,正确答案已经编码到文档中,而\correctchoice
不是 \choice。
我希望它做的是在文档末尾打印一个简单的表格,第一列是问题编号,后面跟着正确答案的字母(如 所示\correctchoice
)。我已经接近了,但唯一存储的答案是最后一个。
我一直在搜索类似的问题,但问题似乎在于将正确的选项与问题标签一起存储在某个地方,然后在最后检索它。我是那些自学成才的 LaTeX 使用者之一,我会将我在其他地方找到的东西拼凑在一起。这是我到目前为止尝试过的方法。它有两个问题,它使每个答案都变成 E,并且它不会自动标记\correctchoice
:
\documentclass[answers
]{exam}
\usepackage{forloop}
\makeatletter
\let\xa=\expandafter
\newcounter{numsolns}
\setcounter{numsolns}{0}
\newcommand\solu{%
%Saves the parameter as a solution
\stepcounter{numsolns}%
%\showthe\c@numsolns
\xa\xdef\csname soln-label-\roman{numsolns}\endcsname{\questionlabel}%
\xa\long\xa\gdef\csname soln-\roman{numsolns}\endcsname{\thechoice}%
}
%The following is from the exam.sty with one change:
\def\CorrectChoice{%
\if@correctchoice
\endgroup
\fi
\ifprintanswers
% We can't say \choice here, because that would
% insert an \endgroup:
\begingroup \@correctchoicetrue
\CorrectChoice@Emphasis
\fi
\item
\do@choice@pageinfo
\solu%
} % CorrectChoice
\let\correctchoice\CorrectChoice
\makeatother
\begin{document}
\begin{questions}
\question[5] Important Question 1
\begin{choices}
\choice 99
\correctchoice 100 \solu
\choice 50
\choice 1
\choice none of these
\end{choices}
\vfill
\question[5] Important Question 2.
\begin{choices}
\CorrectChoice 6 \thechoice \solu
\choice 12
\choice 24
\choice 36
\choice none of these
\end{choices} \answerline \vfill
\end{questions}
\newcounter{loopcounter}
\setcounter{loopcounter}{0}
\begin{center}
\ifnum\arabic{numsolns}>0\relax
\clearpage
\vspace{1in}
\begin{tabular}{|c|c|}\hline
Question & Correct Answer\\\hline
\forloop{loopcounter}{1}{\value{loopcounter} < \arabic{numsolns}}{%
\csname soln-label-\romannumeral\value{loopcounter}\endcsname&
\csname soln-\romannumeral\value{loopcounter}\endcsname \\\hline}
\csname soln-label-\romannumeral\arabic{numsolns}\endcsname&
\csname soln-\romannumeral\arabic{numsolns}\endcsname \\\hline
\end{tabular}
\fi
\end{center}
\end{document}
感谢这些评论,我有一个部分可以工作的例子。
\documentclass[answers
]{exam}
%%%%The following sets up a box to save all the answer information into.
\newbox\allanswers
\setbox\allanswers=\vbox{}
\newenvironment{answer}
{%
\global\setbox\allanswers=\vbox\bgroup%
\unvbox\allanswers%
\thequestion \thechoice\\
}%
{%
\egroup%
}
\newcommand{\showallanswers}{\par\unvbox\allanswers}
%%%%%%%%%%%%%%%%
\makeatletter
\let\xa=\expandafter
%The following is from the exam.sty with one change:
\newcommand{\CorrectChoice}{%
\if@correctchoice
\endgroup
\fi
\ifprintanswers
% We can't say \choice here, because that would
% insert an \endgroup:
\begingroup \@correctchoicetrue
\CorrectChoice@Emphasis
\fi
\item
\do@choice@pageinfo %
} % CorrectChoice
\makeatother
%%%%%%%%%This interacts with the exam.sty to put the answer in the appropriate spot.
\newcommand{\corchoice}[1]{ \CorrectChoice #1 \begin{answer}\end{answer} }
\let\oldCorrectChoice\CorrectChoice
\renewcommand{\CorrectChoice}{\oldCorrectChoice \begin{answer}\end{answer} }
\let\correctchoice\CorrectChoice
\begin{document}
\begin{questions}
\question[5] Important Question 1
\begin{choices}
\choice 99
\corchoice{ 100}
\choice 50
\choice 1
\choice none of these
\end{choices}
\vfill
\question[5] Important Question 2.
\begin{choices}
\corchoice{ 6}
\choice 12
\choice 24
\choice 36
\choice none of these
\end{choices} \answerline \vfill
\end{questions}
\begin{center}
Here are the answers:
\end{center}
\showallanswers
\end{document}
这其中存在几个问题:
我似乎无法将 \newenvironment 更改为 \newcommand,并且使用 \begin{answer}\end{answer} 将信息加载到框中的方式似乎是错误的,但我可以忍受它。
我似乎无法更改 \correctchoice 的定义以使用新环境。我尝试过 \let\oldCorrectChoice\CorrectChoice 之类的 hack,但似乎都不起作用。这可能是因为我正在使用 exam.sty 并试图做一些不可能的事情。
如果 (2) 不可能实现,我真的很想有一个不需要额外数据的命令,就像我现在使用 \corchoice{} 一样,但是当我尝试这样做时,\savebox 会吃掉 \item 号码。
答案1
我从第一个答案开始“单独”显示问题的解决方案并将其修改为几乎完全符合我要求的格式。结果发现 \item 和 \setbox 不能很好地相互配合(请阅读枚举中缺少项目编号了解详情)。
梅威瑟:
\documentclass[answers]{exam}
%%%%The following sets up a box to save all the answer information into.
\newbox\allanswers
\setbox\allanswers=\vbox{}
\newenvironment{answer}
{%
\global\setbox\allanswers=\vbox\bgroup %
\unvbox\allanswers%
\thequestion \thechoice\\
}%
{%
\egroup%
}
\newcommand{\CC}{\CorrectChoice \leavevmode\begin{answer}\end{answer}}% New command \CC replaces \CorrectChoice from exam.sty and saves answers in the box \allanswers .
\newcommand{\showallanswers}{%
\ifprintanswers \centering Here are the answers: \par \usebox\allanswers \fi}
\begin{document}
\begin{questions}
\question[5] Important Question 1
\begin{choices}
\choice 99
\CC 100
\choice 50
\choice 1
\choice none of these
\end{choices}
% \vfill
\question[5] Important Question 2.
\begin{choices}
\CC 6
\choice 12
\choice 24
\choice 36
\choice none of these
\end{choices} \answerline %\vfill
\end{questions}
\showallanswers
% The answers have the same text format as the answers within the question, so are naturally \textbf when
\end{document}
唯一可以使情况变得更好的方法是在表格环境中列出问题编号和答案的列表,但我打算将其留到另一天再做。