
我正在嘗試為我的班級創建一個筆記包,它基本上是一長串問題,一頁有 2 或 3 個問題,每個問題後都有空間,學生可以在其中找到解決方案。我正在使用這個enumitem
包,並且我已經制定了一個幾乎完美的解決方案,使用自訂清單環境並定義itemsep
並after
執行垂直間距工作:
\documentclass{article}
\usepackage[shortlabels]{enumitem}
\newlist{questions}{enumerate}{1}
\setlist[questions]{label=\itshape{{Question }\arabic*.},
ref={Question }\arabic*,
leftmargin=*,
itemindent=*,
itemsep=\fill,
after={\vfill},
resume}
\begin{document}
\begin{questions}
\item First Question
\item Another Question
\item Another Question
\item Another Question
\end{questions}
\end{document}
這工作得很好,直到我決定通過手動插入以下內容將這些問題分散到兩頁上\newpage
:
\begin{document}
\begin{questions}
\item First Question
\item Another Question
\newpage
\item Another Question
\item Another Question
\end{questions}
\end{document}
在此版本中,問題 2 位於第 1 頁的底部,後面沒有空格。我可以透過questions
在新頁面之前結束清單並在之後重新啟動它來修復它,如下所示:
\begin{document}
\begin{questions}
\item First Question
\item Another Question
\end{questions}
\newpage
\begin{questions}
\item Another Question
\item Another Question
\end{questions}
\end{document}
……但是每次我想插入新頁面時結束並重新啟動列表是一件痛苦的事情。
是否有更“優雅”(閱讀:更簡單)的方法來使用 enumitem 包獲得我想要的行為?我非常喜歡 enumitem,除非有充分的理由,否則我寧願不切換到其他軟體包。
答案1
有一個自動\vfil
與\newpage
.它被壓碎了\fill
。
\documentclass{article}
\usepackage[shortlabels]{enumitem}
\newlist{questions}{enumerate}{1}
\setlist[questions]{label=\itshape{{Question }\arabic*.},
ref={Question }\arabic*,
leftmargin=*,
itemindent=*,
itemsep=0pt plus 1fil,
resume}
\begin{document}
\begin{questions}
\item First Question
\item Another Question
\newpage
\item Another Question
\item Another Question
\end{questions}
\end{document}
答案2
問題是\itemsep
黏合是透過命令插入的\item
,因此它位於第二頁的頂部,並根據規則被丟棄。
我認為沒有辦法“回溯”,因為當 TeX 完成一個頁面時,它會將其從記憶體中刪除。因此需要\vfill
在前面手動添加\newpage
。
加入一些語義,你可以這樣做
\newcommand{\questionbreak}{\vfill\pagebreak}
例子:
\documentclass{article}
\usepackage{enumitem}
\newlist{questions}{enumerate}{1}
\setlist[questions]{
label=\textit{Question} \arabic*.,
ref=Question \arabic*,
leftmargin=*,
itemindent=*,
itemsep=\fill,
after=\vfill,
resume,
}
\newcommand{\questionbreak}{\vfill\pagebreak}
\begin{document}
\begin{questions}
\item First Question
\item Another Question
\questionbreak
\item Another Question
\item Another Question
\end{questions}
\end{document}
檢查小的變化:\itshape
不需要爭論。如果您希望數字也以斜體顯示,請執行以下操作
label=\textit{Question \arabic*.}