防止列表元素的第一行成为孤立行

防止列表元素的第一行成为孤立行

我有一个文档,其中包含枚举和逐项列举环境中的长项目列表,其中一些以一行开头,后跟一个长段落(或排序段落):

\begin{itemize}
\item short sentence no more than a line.
% I definitely don't want the page break here
very long paragraph, with lots of text but which 
I wouldn't mind to break between pages.
% I wouldn't mind a break here
\item another item with a some what long sentence
% but it shouldn't break here
Another long paragraph which I wouldn't mind to break.
\end{itemize}

我想防止第一行与文本的其余部分分离,但又不妨碍较长段落的分页符,例如 minipage 或 samepage。似乎有一条注释描述了一段代码ltlists.dtx这似乎是为了防止我看到的情况:

此代码旨在防止在项目第一行后出现分页符紧跟在节标题之后。始终禁止在项目的一行之后分页是明智的吗?与所有此类设置一样,它\clubpenalty是本地的,因此如果项目以组为单位开始,则不会产生任何影响。

但仅适用于标题之后,而这不是特定情况。

答案1

你可以执行\needspace在每个 的开头\item。这将根据页面上剩余的空间量来决定是否应进行分页。

\documentclass{article}

\usepackage{lipsum,needspace,etoolbox,geometry}

\AtBeginEnvironment{itemize}{%
  \let\olditem\item
  \renewcommand{\item}{%
    \par\needspace{\dimexpr\itemsep+2\baselineskip}%
    \olditem}%
}

\geometry{textheight=40\baselineskip}%
%\geometry{textheight=39\baselineskip}% This will make entire second \item go to next page.

\begin{document}

\section{A section}

\lipsum[1-4]

\begin{itemize}
  \item
  Lorem ipsum dolor sit amet, consectetur adipiscing elit. Pellentesque ac 
  mauris fringilla, interdum quam et, tincidunt orci. Duis dictum auctor 
  ante, a ultrices diam pulvinar molestie. Nam massa tellus, tristique et 
  laoreet ut, ultrices vitae tellus.
  Proin feugiat ipsum tortor, non aliquam nisl gravida et. Sed imperdiet 
  arcu aliquam, dictum diam nec, pharetra tortor. Integer id eleifend dolor, 
  vel rhoncus nisi. Nam aliquam leo nisi, quis tincidunt ex sollicitudin nec. 
  Duis vitae ultrices nibh.

  \item
  Lorem ipsum dolor sit amet, consectetur adipiscing elit. Pellentesque ac 
  mauris fringilla, interdum quam et, tincidunt orci. Duis dictum auctor 
  ante, a ultrices diam pulvinar molestie. Nam massa tellus, tristique et 
  laoreet ut, ultrices vitae tellus.
  Proin feugiat ipsum tortor, non aliquam nisl gravida et. Sed imperdiet 
  arcu aliquam, dictum diam nec, pharetra tortor. Integer id eleifend dolor, 
  vel rhoncus nisi. Nam aliquam leo nisi, quis tincidunt ex sollicitudin nec. 
  Duis vitae ultrices nibh.

\end{itemize}

\lipsum[1-4]

\end{document}

etoolbox进入itemize环境,更新\item以检查\itemsep+2\baselineskip页面上的剩余内容。您可能需要尝试使用这些值才能在特定情况下发挥作用。

相关内容