0

I have a document with a long list of items in enumerate and itemize environments, some of these start with a single line followed of a long (or sort) paragraph:

\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}

I want to prevent the first line from being separated from the rest of the text, but in a way that doesn't prevent page breaks on the longer paragraphs, like minipage or samepage. There seems to be a comment describing a piece of code from ltlists.dtx that seems to be meant to prevent the case I'm seeing:

This code is intended to prevent a page break after the first line of an item that comes immediately after a section title. It may be sensible to always forbid a page break after one line of an item? As with all such settings of \clubpenalty it is local so will have no effect if the item starts in a group.

But only applies if it's after a title, which is not this specific case.

  • 1
    Welcome to TeX.SX! Can you please expand the code snippet that you have posted to a full minimal working example. A MWE should compile and be as small as possible to demonstrate your problem. it's much easier to help you if we have full working code to start from. – Andrew Nov 28 '16 at 3:21
  • There aren't any paragraphs in what you've shown. But a paragraph break is a better page break than in the middle of a paragraph, typographically. I suspect that you should not be using an itemize environment here and that you really want something else. – cfr Nov 28 '16 at 3:25
  • @Andrew the problem is representable by what I've shown. There isn't anything "fancy" about it. – Braiam Nov 28 '16 at 3:28
  • @cfr it's a list of elements with a short introductory line, and then paragraphs. I don't know how how else to represent them other than using enumerate/itemize. – Braiam Nov 28 '16 at 3:29
  • As far as I can see your code does not compile, it doesn't contain paragraphs and it doesn't produce any widows. So, sorry, but I don't think it's a MWE :) The point of providing a MWE is that it gives people have something to work from or, if you like, some code to fix. To ask people to construct an example that exhibits your problem and then solve it is a little OTT. A MWE also clarifies exactly what your problem is and so avoids people wasting their time solving a different problem. – Andrew Nov 28 '16 at 3:41
2

You could execute \needspace at the start of every \item. This will decide whether a page break should be made or not, depending on the amount of space left on the page.

\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 taps into the itemize environment, updating \item to check for \itemsep+2\baselineskip remaining on the page. You may have to play around with these values to get something to work in your specific case.

  • I've set textheight at 45 which seems to be the best not creating widows or orphans later. – Braiam Nov 28 '16 at 13:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.