默认情况下,LaTeX 允许在节/小节标题后的前两行段落后进行分页,但我想将节标题及其下方的一行保留在当前页面的底部。怎么做?
请注意,我不想使用任何其他软件包,例如 etoolbox 或 needspace。
这是我的 MWE:
\documentclass{book}
\usepackage[showframe]{geometry}% just for this example
\usepackage{lipsum}
\newcommand{\dummy}{This is a test }
\begin{document}
\lipsum[1-6]
\section{bla}
This is a test This is a test This is a test This is a test
This is a test This is a test This is a test
This is a test
\end{document}
答案1
无需任何附加软件包,在序言中添加以下几行
\makeatletter
\renewcommand\@afterheading{%
\@nobreaktrue
\everypar{%
\if@nobreak
\@nobreakfalse
\clubpenalty 1
\if@afterindent \else
{\setbox\z@\lastbox}%
\fi
\else
\clubpenalty 1
\everypar{}%
\fi}}
\makeatother
梅威瑟:
\documentclass{book}
\usepackage[showframe]{geometry}% just for this example
\usepackage{lipsum}
\newcommand{\dummy}{This is a test }
\makeatletter
\renewcommand\@afterheading{%
\@nobreaktrue
\everypar{%
\if@nobreak
\@nobreakfalse
\clubpenalty 1
\if@afterindent \else
{\setbox\z@\lastbox}%
\fi
\else
\clubpenalty 1
\everypar{}%
\fi}}
\makeatother
\begin{document}
\lipsum[1-6]
\section{bla}
This is a test This is a test This is a test This is a test
This is a test This is a test This is a test
This is a test
\end{document}
输出:
答案2
\documentclass{book}
\usepackage[showframe]{geometry}% just for this example
\usepackage{lipsum}
\newcommand\dummy{This is a test }
\widowpenalty=-1000 %%%%%%%%%%%%%%%%%%%%%%%%%%
\clubpenalty=-1000 %%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{document}
\lipsum[1-6]
\section{bla}
This is a test This is a test This is a test This is a test
This is a test This is a test This is a test
This is a test
\end{document}