我使用这个exercise
软件包制作了由一系列小问题组成的练习表。
由于我使用两列布局,因此经常会遇到分页符/列符,有时它会在难看的地方中断练习:请参阅以下 MWE 中的练习 3。练习 2 之后的中断应该会更好。
\documentclass[a4paper,11pt, twocolumn]{article}
\usepackage[utf8]{inputenc}
\usepackage{exercise}
\usepackage{lipsum}
\begin{document}
\begin{Exercise}
A small sentence to describe the context of this small exercise.
\Question{Please fill this table:}
\begin{tabular}{|l|l|l|l|}\hline
A & B & C & ??\\\hline
A & B & C & ??\\\hline
A & B & C & ??\\\hline
A & B & C & ??\\\hline
A & B & C & ??\\\hline
\end{tabular}
\Question{Can you answer this question?}
\Question{And this one?}
\Question{And this other one ?}
\end{Exercise}
\begin{Exercise}
\lipsum[1]
\Question{Can you answer this question?}
\Question{And this one?}
\Question{And this other one ?}
\end{Exercise}
\begin{Exercise}
A small sentence to describe the context of this small exercise.
\Question{Please fill again this table:}
\begin{tabular}{|l|l|l|l|}\hline
A & B & C & ??\\\hline
A & B & C & ??\\\hline
A & B & C & ??\\\hline
A & B & C & ??\\\hline
A & B & C & ??\\\hline
\end{tabular}
\Question{Can you answer this question?}
\Question{And this one?}
\end{Exercise}
\begin{Exercise}
\lipsum[1]
\Question{Can you answer this question?}
\end{Exercise}
\end{document}
我怎样才能优先休息之间环境而不是之内可以吗?请注意,我并不想完全禁止分页符/列分隔符。
这\nopagebreak[number]
对我来说似乎很合适,但如何将它应用到像这样的整个环境中Exercise
?
答案1
我终于找到了这里\needspace
使用来自包的命令的解决方案needspace
:
[它的] 参数告诉您需要多少空间。如果空间不足,则清除当前页面,并将需要保存的内容插入到新页面上。
以下是我修改后的 MWE:
\documentclass[a4paper,11pt, twocolumn]{article}
\usepackage[utf8]{inputenc}
\usepackage{exercise}
\usepackage{lipsum}
\usepackage{needspace}
\let\oldExerciseHeader\ExerciseHeader
\def\ExerciseHeader{\needspace{4\baselineskip}\oldExerciseHeader} % Redefine Exercise header to include needspace command.
\begin{document}
\begin{Exercise}
A small sentence to describe the context of this small exercise.
\Question{Please fill this table:}
\begin{tabular}{|l|l|l|l|}\hline
A & B & C & ??\\\hline
A & B & C & ??\\\hline
A & B & C & ??\\\hline
A & B & C & ??\\\hline
A & B & C & ??\\\hline
\end{tabular}
\Question{Can you answer this question?}
\Question{And this one?}
\Question{And this other one ?}
\end{Exercise}
\begin{Exercise}
\lipsum[1]
\Question{Can you answer this question?}
\Question{And this one?}
\Question{And this other one ?}
\end{Exercise}
% \begin{samepage}
\begin{Exercise}
A small sentence to describe the context of this small exercise.
\Question{Please fill again this table:}
\begin{tabular}{|l|l|l|l|}\hline
A & B & C & ??\\\hline
A & B & C & ??\\\hline
A & B & C & ??\\\hline
A & B & C & ??\\\hline
A & B & C & ??\\\hline
\end{tabular}
\Question{Can you answer this question?}
\Question{And this one?}
\end{Exercise}
% \end{samepage}
\begin{Exercise}
\lipsum[1]
\Question{Can you answer this question?}
\end{Exercise}
\end{document}
当然,保留的长度(4\baselineskip
)可以根据您的需要进行更改。