如何使用 `exams2nops` 在 `exams` 生成的 pdf 中添加一行?

How to add a line in the pdf generated pdf by `exams` using the `exams2nops`?

我们正在通过 exams2nops 使用选择块中的项目生成 pdf,我们想在每个块的最后一个练习之后添加一条水平线来分隔 PDF 中的块。考虑到这一点,我们添加了 ***---<hr/>,但行为始终相同:

我想要单行而不添加考试中的下一个练习编号:

把水平线放到练习文件里,不是那么容易解决的。原因是 答案列表之后需要该行,但练习中没有格式化答案列表,而是 exams2nops.

解决方法是调整 exams2nops 使用的 LaTeX 模板中 {question} 环境的定义。默认情况下,这很简单:

\newenvironment{question}{\item}{}

其中 \item{question} 的开头执行,而在它的末尾什么也不执行。通过

更改此设置
\renewenvironment{question}{\item}{\hrulefill}

会在每个问题后插入一条水平线。如果您只想在选定的问题之后使用它,则需要为某些枚举项插入 if/else 语句。例如只在第二项后插入水平线,可以重新定义:

\renewenvironment{question}{\item}{\ifnum\value{enumi}=2 {\hrulefill} \else {} \fi}

因此,您从您使用的 {enumerate} 环境中获取 enumi 计数器并将其与 2 进行比较。如果为真,则插入水平线,否则什么都不做。

为反斜杠添加转义,您可以通过 header 参数将此重新定义传递给 exams2nops

exams2nops(c("swisscapital", "switzerland", "tstat2", "deriv2"),
  header = "\renewenvironment{question}{\item}{\ifnum\value{enumi}=2 {\hrulefill} \else {} \fi}")

结果输出为: