使用LaTaX制作试卷
Typesetting exams LaTeX
原 文:Pgfplots package
译 者:Xovee
翻译时间:2023年12月2日
文章目录
介绍
我们可以使用LaTeX内置的exam.cls来轻松制作试题。你还可以使用它来显示和计算成绩。我们首先将文档格式设置为exam:
\documentclass{exam}
然后我们就可以使用一些制作试卷的特殊命令,并且页边距也会加大(来让老师们有空间改卷)。
基础
让我们来看一个简单的例子:
\documentclass{exam}
\begin{document}
\begin{center}
\fbox{\fbox{\parbox{5.5in}{\centering
Answer the questions in the spaces provided. If you run out of room
for an answer, continue on the back of the page.}}}
\end{center}
\vspace{5mm}
\makebox[0.75\textwidth]{Name and section:\enspace\hrulefill}
\vspace{5mm}
\makebox[0.75\textwidth]{Instructor’s name:\enspace\hrulefill}
\begin{questions}
\question Is it true that \(x^n + y^n = z^n\) if \(x,y,z\) and \(n\) are
positive integers?. Explain.
\question Prove that the real part of all non-trivial zeros of the function
\(\zeta(z)\) is \(\frac{1}{2}\)
\question Compute \[\int_{0}^{\infty} \frac{\sin(x)}{x}\]
\end{questions}
\end{document}

questions环境的语法与itemize或者enumerate环境非常类似。每个问题都由\question命令开始。
上面例子中的其它命令并不是exam自带的,但是你可以使用它们来创建一个试卷页眉或标题。
创建新问题
前面我们展示了一个简单的创建问题的例子。你还可以进一步自定义问题的样式。
\begin{questions}
\question Is it true that \(x^n + y^n = z^n\) if \(x,y,z\) and \(n\) are positive integers?. Explain.
\vspace{\stretch{1}}
\question Prove that the real part of all non-trivial zeros of the function \(\zeta(z)\) is \(\frac{1}{2}\)
\vspace{\stretch{1}}
\question Compute \[\int_{0}^{\infty} \frac{\sin(x)}{x}\]
\vspace{\stretch{1}}
\end{questions}
\clearpage

在这里我们使用\vspace{\stretch{1}}命令来在每个问题后面添加空白空间。并且每个问题之后的空白空间的大小是一致的,即每个问题之后的空间是剩余可用空间中的三分之一。
命令\clearpage设置当前页的结束,然后我们就可以在新的一页中创建新的问题。
如果你想手动给每个问题设置自定义的空白空间,使用\vspace{}命令然后在大括号中输入空白空间的大小。例如,\vspace{1in}命令会在页面中插入一段长为一英尺的空白空间。你可以在这篇文章中找到更多有关LaTeX中单位的信息。
子问题(subparts)
如果试卷中的问题有多个子问题的话,你可以使用parts、subparts和subsubparts环境(以及相应的\part、\subpart和\subsubpart)来做到这一点。请看下面的例子:
\begin{questions}
\question Given the equation \(x^n + y^n = z^n\) for \(x,y,z\) and \(n\) positive
integers.
\begin{parts}
\part For what values of \(n\) is the statement in the previous question true?
\vspace{\stretch{1}}
\part For \(n=2\) there's a theorem with a special name. What's that name?
\vspace{\stretch{1}}
\part What famous mathematician had an elegant proof for this theorem but
there was not enough space in the margin to write it down?
\vspace{\stretch{1}}
\begin{subparts}
\subpart Who actually proved the theorem?
\vspace{\stretch{1}}
\subpart How long did actually take to solve this problem?
\vspace{\stretch{1}}
\end{subparts}
\end{parts}
\question Prove that the real part of all non-trivial zeros of the function
\(\zeta(z)\) is \(\frac{1}{2}\)
...
\end{questions}

parts和subparts环境设置了一种层级的问题列表。你在这些环境中也可以手动设置空白空间。
多选题
LaTeX有四种环境用于创建多选题。
\begin{questions}
\question Which of these famous physicists invented time?
\begin{oneparchoices}
\choice Stephen Hawking
\choice Albert Einstein
\choice Emmy Noether
\choice This makes no sense
\end{oneparchoices}
\question Which of these famous physicists published a paper on Brownian Motion?
\begin{checkboxes}
\choice Stephen Hawking
\choice Albert Einstein
\choice Emmy Noether
\choice I don't know
\end{checkboxes}
\end{questions}

这个例子中有两个不同的环境用于创建多选题。
oneparchoices使用大写字母来标记每个选项,并且选项是水平排列的。如果你想纵向排列,使用choices环境。checkboxes环境为每个选项都创建一个圆圈标记。如果你想横向排列,使用oneparcheckboxes环境
记分(grading)
exam中另一个重要的功能是记分。
每道题的得分
你可以给每个\question或者\part添加一个参数,来给这道题进行赋分。在命令后的方括号中使用这个参数。请看例子:
\begin{questions}
\question Given the equation \(x^n + y^n = z^n\) for \(x,y,z\) and \(n\) positive
integers.
\begin{parts}
\part[10] For what values of \(n\) is the statement in the previous question true?
\vspace{\stretch{1}}
\part[10] For \(n=2\) there's a theorem with a special name. What's that name?
\vspace{\stretch{1}}
\part[10] What famous mathematician had an elegant proof for this theorem but there was
not enough space in the margin to write it down?
\vspace{\stretch{1}}
\end{parts}
\question[20] Compute \[\int_{0}^{\infty} \frac{\sin(x)}{x}\]
\vspace{\stretch{1}}
\end{questions}

算分和一半分(counting points and half points)
有时候我们需要对一道题的不同子题赋于一半分(half points)。请看下面的例子(我们在题的结尾打印了题的总分)
\documentclass[addpoints]{exam}
\begin{document}
\begin{questions}
\question Given the equation \(x^n + y^n = z^n\) for \(x,y,z\) and \(n\) positive
integers.
\begin{parts}
\part[5] For what values of \(n\) is the statement in the previous question true?
\vspace{\stretch{1}}
\part[2 \half] For \(n=2\) there's a theorem with a special name. What's that name?
\vspace{\stretch{1}}
\part[2 \half] What famous mathematician had an elegant proof for this theorem but there was
not enough space in the margin to write it down?
\vspace{\stretch{1}}
\end{parts}
\droptotalpoints
\question[20] Compute \[\int_{0}^{\infty} \frac{\sin(x)}{x}\]
\end{questions}
\end{document}

命令\half对题目添加了0.5分。命令\droptotalpoints在最后一道小题之后打印了这道题的总分。为了实现这个功能,你需要在文档类型的命令中传递[addpoints]参数。
奖励分
你还可以对题目添加奖励分。奖励分也会显示在得分表中(我们之后会讲)。请看例子:
\begin{questions}
\question Given the equation \(x^n + y^n = z^n\) for \(x,y,z\) and \(n\) positive
integers.
\begin{parts}
\part[5] For what values of \(n\) is the statement in the previous question true?
\vspace{\stretch{1}}
\part[2 \half] For \(n=2\) there's a theorem with a special name. What's that name?
\vspace{\stretch{1}}
\bonuspart[2 \half] What famous mathematician had an elegant proof for this theorem but there was
not enough space in the margin to write it down?
\vspace{\stretch{1}}
\end{parts}
\droptotalpoints
\question[20] Compute \[\int_{0}^{\infty} \frac{\sin(x)}{x}\]
\vspace{\stretch{1}}
\bonusquestion[30] Prove that the real part of all non-trivial zeros of the function
\(\zeta(z)\) is \(\frac{1}{2}\)
\vspace{\stretch{1}}
\end{questions}

命令\bonusquestion和\bonuspart会在题目的分数之后添加bonus子样。
得分表
我们可以使用一个特殊的命令来显示试卷的得分表:
\begin{center}
\combinedgradetable[h][questions]
\end{center}

总共有三个命令可以打印得分表:
\gradetable:不显示奖励分\bonusgradetable:只打印奖励分题目\combinedgradetable:都打印
这些命令接受两个额外的参数:
- 第一个参数。
[h]:水平方向的表;[v]:纵向的表 - 第二个参数。
[questions]:每道题的分数;[pages]:每页题的分数。
Overleaf exam 项目示例
上面的例子加起来可以当作一个创作试卷的初始模板。你可以点击这个链接来使用这个Overleaf模版。
其它语言
exam包不支持除英语以外的语言。不过将各种关键词翻译为你想要的语言是很容易的。让我们来看一个西班牙语的例子:
\usepackage[spanish]{babel}
\pointpoints{punto}{puntos}
\bonuspointpoints{punto extra}{puntos extra}
\totalformat{Pregunta \thequestion: \totalpoints puntos}
\chqword{Pregunta}
\chpgword{Página}
\chpword{Puntos}
\chbpword{Puntos extra}
\chsword{Puntos obtenidos}
\chtword{Total}
...


命令解释:
\pointpoints{punto}{puntos}:将point变为punto,将points变为puntos\bonuspointpoints{punto extra}{puntos extra}:将bonus point和bonus points变为punto extra和puntos extras\totalformat{Pregunta \thequestion: \totalpoints puntos}:将droptotalpoints命令显示的总分文字变为Pregunta \thequestio: \totalpoints puntos。在这里,会显示为Pregunta 1: 7 1/2 puntos。\chqword{Pregunta}:在分数表中将Question文字变为Pregunta。其它类似命令的作用是相似的。chpgword:Pagechpword:Pointschbpdord:Bonus pointschsword:Scorechtword:Total
文末列出了更多的命令。
参考指南
调整题目记号的位置和样式
下面介绍的命令可以用来改变题目记号的位置和样式。命令放在preamble中会改变整个文档的样式。放在正文中会改变命令之后,下个命令之前的内容的样式(如果没有下一个同类型命令,则直至文末都为该样式)。
\pointsinmargin(或\pointsinleftmargin)会把题目分数显示在左侧页边距中。\pointsinrightmargin:右侧页边距\nopointsinmargin(或\nopointsinrightmargin):取消上面两个命令的作用,回到默认的设置\bracketedpoints:在方括号中而不是小括号中来显示分数\boxedpoints:在方框中显示分数
下面的例子使用了pointsinmargin和pointsinrightmargin命令:
Here we'll use \verb|\pointsinmargin|
\begin{questions}
\pointsinmargin
\question Given the equation \(x^n + y^n = z^n\) for \(x,y,z\) and \(n\) positive
integers.
\begin{parts}
\part[5] For what values of \(n\) is the statement in the previous question true?
\vspace{40pt}
\part[2 \half] For \(n=2\) there's a theorem with a special name. What's that name?
\vspace{40pt}
\part[2 \half] What famous mathematician had an elegant proof for this theorem but there was
not enough space in the margin to write it down?
\vspace{40pt}
\end{parts}
Now we'll use \verb|\pointsinrightmargin|
\pointsinrightmargin
\question Given the equation \(x^n + y^n = z^n\) for \(x,y,z\) and \(n\) positive
integers.
\begin{parts}
\part[5] For what values of \(n\) is the statement in the previous question true?
\vspace{40pt}
\part[2 \half] For \(n=2\) there's a theorem with a special name. What's that name?
\vspace{40pt}
\part[2 \half] What famous mathematician had an elegant proof for this theorem but there was
not enough space in the margin to write it down?
integers.
\end{parts}
\end{questions}

改变得分表中的默认文字
在下面的表格中,h和v分别代表水平和垂直方向。如果命令之前有一个b,则代表改变的是奖励分表格;c代表改变的是总表(正常分和奖励分都有)。例如,当你想把一个垂直的奖励分表格中的Score改为Points Awarded,你应该使用\bvsword{Points Awarded}命令。
| grades table | horizontal | vertical |
|---|---|---|
| Question: | \hqwrod{Question:} | \vqwrod{Question} |
| Page: | \hpgword{Page:} | \vpgword{Page} |
| Points: | \hpword{Points:} | \vpword{Points} |
| Score: | \hsword{Score:} | \vswrod{Score} |
| Total | \htword{Total} | \vtword{Total:} |
| bonus points table | horizontal | vertical |
|---|---|---|
| Question: | \bhqwrod{Question:} | \bvqwrod{Question} |
| Page: | \bhpgword{Page:} | \bvpgword{Page} |
| Bonus Points: | \bhpword{Bonus Points:} | \bvpword{Bonus Points} |
| Score: | \bhsword{Score:} | \bvswrod{Score} |
| Total | \bhtword{Total} | \bvtword{Total:} |
| combined table | horizontal | vertical |
|---|---|---|
| Question: | \chqwrod{Question:} | \cvqwrod{Question} |
| Page: | \chpgword{Page:} | \cvpgword{Page} |
| Points: | \chpword{Points:} | \cvpword{Points} |
| Bonus Points: | \chbpword{Bonus Points:} | \cvbpword{Bonus Points} |
| Score: | \chsword{Score:} | \cvswrod{Score} |
| Total | \chtword{Total} | \cvtword{Total:} |