我使用考试类在我的几门课程中编写多项选择题测试。我使用以下代码收集正确答案,然后在测试结束时使用命令 \showallanswers 显示正确答案。
%%%%%start code for printing answers
\CorrectChoiceEmphasis{} %% removes question answers being boldface on test
\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}
%%%%%end code for printing answers
只要测试包含约 35 个或更少的问题,这种方法就完美了。如果测试包含更多问题,则答案键会被截断,并且不会显示超过 35 个的所有答案。我怀疑这是因为使用 vbox 来显示答案,而单个页面没有足够的行数。如果您能帮助修改上述代码以适应更长的测试,我将不胜感激。如果需要,有没有办法让答案键使用两列?我尝试编辑代码并应用 multicols 包,但我的宏制作技巧并不好。
提前非常感谢您。
这是一个更完整的 MWE,它可以编译整个文档:
\documentclass[addpoints,answers]{exam}
\usepackage[margin=1in]{geometry}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{graphicx}
\usepackage{multicol}
\footer{}{Page \thepage}{}
\pagestyle{headandfoot}
\title{Exam Title}
\header{Course}{Test 1 --- Form A}{Spring 2023}
%\footer{Page \thepage\ of \numpages}
%{}
%{Points earned: \makebox[.5in]{\hrulefill}\\
%out of a possible \pointsonpage{\thepage} points}
%%%%%start code for printing answers
\CorrectChoiceEmphasis{} %% removes question answers being boldface on test
\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}
%%%%%end code for printing answers
\begin{document}
\begin{center}
\fbox{\fbox{\parbox{5.5in}{\centering
INSERT EXAM INSTRUCTIONS HERE.}}}
\end{center}
\vspace{0.1in}
\makebox[\textwidth]{Name:\enspace\hrulefill} \\
\begin{questions}
\question[2] What is the answer?
\begin{choices}
\choice Option 1
\choice Option 2
\CC Option 3
\choice Option 4
\end{choices}
\end{questions}
\newpage
\showallanswers
\end{document}
答案1
我通过查看帖子找到了解决方案
线路
\ifprintanswers \centering Here are the answers: \par \usebox\allanswers \fi}
被修改为
\ifprintanswers \centering Here are the answers: \par \unvbox\allanswers \fi}
然后答案列表被分成多页。