我正在使用这个exam
课程,我想添加答案。目前答案打印在问题之后,但在下一个问题之前。理想情况下,它们应该在一系列问题的末尾呈现。我希望
- 问题的数字或非常简单的一行答案(例如新
\begin{numans} ... \end{numans}
环境),或 - 整个解决方案与现在的环境一样
solution
,
在文档末尾。有什么想法吗?
MWE:
\documentclass[a4paper]{exam}
\usepackage[utf8]{inputenc}
\printanswers
\begin{document}
\begin{questions}
\addpoints \question This is the first question
\begin{solution}
This is the solution to question one.
\end{solution}
\addpoints \question This is the second question
\begin{solution}
This is the solution to questino two.
\end{solution}
\end{questions}
\end{document}
编辑:Erik 建议的解决方案是可行的,但我希望能够坚持我已经exam
分类的文档。
答案1
假设您想在每个问题后输入答案(就像您现在拥有的那样),但要收集它们并定期将它们显示在一个组中。这正是尾注的工作方式,所以我会使用其中一个尾注包:它们似乎都支持多组尾注,没有任何麻烦。这是一个使用旧的概念证明endnotes.sty
。您可以轻松调整它以获得所需的外观,自动编号答案等。
\documentclass[a4paper]{exam}
\usepackage[utf8]{inputenc}
\printanswers
\usepackage{url}
\usepackage{endnotes}
\def\enotesize{\normalsize}
\def\makeenmark{\relax}
\def\notesname{Answers}
\def\answer#1{\endnotetext{\vspace*{-3.5ex}\begin{solution}#1\end{solution}\unskip}}
\def\theanswers{\theendnotes \medskip}
\begin{document}
\begin{questions}
\addpoints \question This is the first question
\answer{This is the solution to question one.}
\addpoints \question This the second question
\answer{This is the solution to question two.}
\end{questions}
\theanswers
\end{document}
请注意,您可以根据需要多次调用\theanswers
(即),它将输出累积的答案并清除尾注文件。\theendnotes
编辑:用一些技巧对其进行了调整,以减少解决方案之间的间距。实际上,空间来自环境solution
,因此应该通过修改其行为来修复,但很难追踪哪个宏到底负责多少垂直空间。
endnote 包enotez
是另一种选择,但endnotes.sty
更简单,因此更容易被黑客入侵。
答案2
这是一个带有答案包的解决方案
\documentclass[a4paper]{exam}
\usepackage[utf8]{inputenc}
\usepackage{answers}
\Newassociation{sol}{Sol}{mycor}
\renewcommand{\Sollabel}[1]{\textbf{Solution #1.}}
\printanswers
\begin{document}
\Opensolutionfile{mycor}
\ifprintanswers
\renewenvironment{Sol}[1]{%
\framed\noindent\Sollabel{#1}}{\endframed}%
\else
\answerfilestrue
\renewcommand{\Readsolutionfile}[1]{}\fi
\begin{questions}
\addpoints
\begin{question} This is the first question
\begin{sol}
This is the solution to question one.
\end{sol}
\end{question}
\addpoints
\begin{question} This is the first question
\end{question}
\addpoints
\begin{question} This is the first question
\begin{sol}
This is the solution to question one.
\end{sol}
\end{question}
\end{questions}
\Closesolutionfile{mycor}
\Readsolutionfile{mycor}
\end{document}
如果你想在问题之后立即得到解决方案
\usepackage[nosolutionfiles]{answers}
答案3
exam
支持重新定义解决方案环境。请参阅第 66 页这个文件,第 8.3.3 节。只需创建一个具有计数器的环境:
\documentclass[a4paper]{exam}
\usepackage[utf8]{inputenc}
\printanswers
\begin{document}
\begin{questions}
\addpoints \question This is the first question
\addpoints \question This is the second question
\newcounter{solcounter}
\newcommand{\solcount}{\stepcounter{solcounter}\arabic{solcounter}. }
\renewenvironment{TheSolution}{
\solcount
}
\begin{solution}
This is the solution to question one.
\end{solution}
\begin{solution}
This is the solution to question two.
\end{solution}
\end{questions}
\end{document}
答案4
如同alexis 的回答而是用endnotes
包中,expl3
将每个解决方案存储在一个seq
变量中
\documentclass[a4paper]{exam}
\usepackage{xparse}
\printanswers
\ExplSyntaxOn
\seq_new:N \l_exam_endprint_seq
\NewDocumentCommand \WriteAnswer { +m } { \seq_gput_right:Nn \l_exam_endprint_seq { #1 } }
\NewDocumentCommand \EndPrintAnswers { } {
\seq_map_inline:Nn \l_exam_endprint_seq { \begin{solution} ##1 \end{solution} }
}
\ExplSyntaxOff
\begin{document}
\begin{questions}
\addpoints \question This is question one.
\WriteAnswer{This is the solution to question one.}
\addpoints \question This is question two.
\WriteAnswer{This is the solution to question two.}
\addpoints \question This is the third question
\WriteAnswer{This is the solution to question three.}
\end{questions}
\EndPrintAnswers
\end{document}
如果需要,可以通过添加计数器来引入编号(如果问题有部分,这将产生问题)。应将以下内容添加到序言中
\newcounter{solution}
\stepcounter{solution}
\renewcommand{\solutiontitle}{\noindent\textbf{Solution \arabic{solution}:}\enspace\stepcounter{solution}}
正如该问题其他地方所指出的,调整连续环境之间的间距solution
可能是可取的。