【问题标题】:R/exams: prevent page breaks between two paragraphs in exams2nopsR/exams:防止exams2nops中两段之间的分页符
【发布时间】:2020-09-26 22:53:07
【问题描述】:

我目前正在使用 R/exams 软件包,特别是使用 exams2nops 函数创建考试,并且问题的顺序是随机的。除了一个细节外,一切都很好:samepage = TRUE 选项只能防止段落中的分页符。但是,出于我的目的,有必要不要拆分任何练习。在一个文本中仍然可以只写一个段落(尽管这对清晰没有帮助)。不幸的是,每当我需要包含一个表格时,我都不得不开始一个新段落,该段落不受分页“保护”。由于随机化,总会有一些副本,其中文本和表格被拆分为多个页面。我尝试了 .Rmd 和 .Rnw 文件,还尝试集成一些 LaTeX 函数,例如 \nopagebreak\needspace,但均未成功。到目前为止,我对 LaTeX 并没有太多经验,而且在 Google 的帮助下我也没有找到解决方案。

这是我所说的练习类型的一个最小示例:

.Rmd

Question
========
Some kind of question:

| A | B | C |
|:-:|:-:|:-:|
| 1 | 2 | 3 |
| 1 | 2 | 3 |
| 1 | 2 | 3 |
| 1 | 2 | 3 |
| 1 | 2 | 3 |

Answerlist
----------
* First option
* Second option
* Third option

Some further informational text.

.Rnw

\begin{question}
Some kind of question:
\begin{center}
\begin{tabular}{ccccccr}
$\text{A}$ & $\text{B}$ & $\text{C}$ \\
$\text{1}$ & $\text{2}$ & $\text{3}$ \\
$\text{1}$ & $\text{2}$ & $\text{3}$ \\
$\text{1}$ & $\text{2}$ & $\text{3}$ \\
$\text{1}$ & $\text{2}$ & $\text{3}$ \\
$\text{1}$ & $\text{2}$ & $\text{3}$ \\
\end{tabular}
\end{center}
Some further informational text.
\begin{answerlist}
  \item First option
  \item Second option
  \item Third option
\end{answerlist}
\end{question}

我不确定要尝试什么。

【问题讨论】:

    标签: r latex r-exams


    【解决方案1】:

    samepage = TRUE 选项仅强制 {answerlist} 位于 {samepage} 环境中 - 而不是整个 {question}

    完成您想做的最简单的选择似乎是在header = 参数中重新定义{question} 环境。您可以尝试通过

    将所有内容放入{samepage} 环境中
    exams2nops(...,
      header = "\\renewenvironment{question}{\\item \\begin{samepage}}{\\end{samepage}}")
    

    不过,这可能必须与段落之间的一些\nopagebreak 命令相结合。 (见:Make an unbreakable block in TeX

    一个更简单的解决方案可能是将每个练习放在自己的页面上,方法是在每个练习的末尾添加一个分页符:

    exams2nops(...,
      header = "\\renewenvironment{question}{\\item}{\\newpage}")
    

    如果你不熟悉上面的 LaTeX 语法:

    • \renewenvironment{foo}{...}{...} 重新定义环境“foo”。
    • 第一个... 是在环境开始时执行的内容。
    • 第二个... 在最后执行。
    • 默认情况下,一开始只执行\item,以增加练习的枚举计数器。
    • 在 R 中需要使用双反斜杠(例如 \\item)来转义反斜杠,因为它们是特殊字符。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-03-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多