# keeping the last line of one paragraph with the first line of the next paragraph or list in a \raggedbottom context

I often introduce new text with the last line of a paragraph, terminated by a colon. Perhaps the text before and after is ordinary text (between pages 1 and 2 in the example), or the text thereafter is a list (between pages 3 and 4 in the example), or the first paragraph is within a list with the next one being in a nested list (between pages 5 and 6 in the example). I would like to keep the last line of the first paragraph with the subsequent paragraph because that last line is often of an introductory nature. How can I do this? (I know about \Needspace, but I don't know how to use it for a solution here.)

I believe this question makes most sense in a \raggedbottom-context; this is also where I need this resolved. Here is an example:

\documentclass{memoir}
\usepackage{lipsum}
\raggedbottom

\begin{document}

\lipsum[1-4]
Some filler text. Some filler text. Some filler text. Some filler text. Some filler text. Some filler text. Some filler text. Some filler text. Some filler text. Some filler text. Some filler text. Some filler text. Some filler text. Some filler text. Some filler text. Some filler text. Some filler text. Some filler text. Some filler text. Some filler text. Some filler text. Some filler text. Some filler text. Some filler text. Some filler text. Some filler text. Some filler text. Some filler text. Some filler text. Some filler text. Some filler text. Some filler text. Some filler text. Some filler text. Some filler text. Some filler text. Some filler text. Some filler text:

Some filler text. Some filler text.

\newpage

\lipsum[1-4]
Some filler text. Some filler text. Some filler text. Some filler text. Some filler text. Some filler text. Some filler text. Some filler text. Some filler text. Some filler text. Some filler text. Some filler text. Some filler text. Some filler text. Some filler text. Some filler text. Some filler text. Some filler text. Some filler text. Some filler text. Some filler text. Some filler text. Some filler text. Some filler text. Some filler text. Some filler text. Some filler text. Some filler text. Some filler text. Some filler text. Some filler text. Some filler text. Some filler text. Some filler text. Some filler text. Some filler text. Some filler text. Some filler text:

\begin{itemize}
\item Some text.
\item Some text.
\item Some text.
\end{itemize}

\newpage

\begin{itemize}
\item \lipsum[1-4]
\item Some filler text. Some filler text. Some filler text. Some filler text. Some filler text. Some filler text. Some filler text. Some filler text. Some filler text. Some filler text. Some filler text. Some filler text. Some filler text. Some filler text. Some filler text. Some filler text. Some filler text. Now a nested list:
\begin{itemize}
\item Some text.
\item Some text.
\item Some text.
\end{itemize}
\end{itemize}

\end{document}


Here I would specifically like the last lines of pages 1, 3, and 5 kept together with the first lines of pages 2, 4, and 6, respectively. \nopagebreak works in the first case, but not in the two list cases.

-
Having the blank line before the itemize is a markup error, if the preceding text ends with : then the list is part of the same sentence so part of the same paragraph, LaTeX goes to a lot of effort to distinguish in-paragraph lists from end or start of paragraph lists –  David Carlisle Jan 22 '13 at 10:15
the blank line problem is also a markup error before a math display, with the same unwanted result. –  barbara beeton Jan 22 '13 at 15:50
@barbarabeeton Yes it's actually much worse before a (primitive tex) math display as you get a blank paragraph in that case (an hbox just containing indentation and parfillskip glue) rather than just different vertical glue –  David Carlisle Jan 23 '13 at 0:43

Some filler text. Some filler text. Some filler text. Some filler text. Some filler text. Some filler text:
\widowpenalty=-5000 \nopagebreak
\begin{itemize}
\item Some text.
\item Some text.
\item Some text.
\end{itemize}


pushes

Some filler text:


To the top of page 4. The negative widow penalty encourages rather than discourages a break before the last line of the partial paragraph and the \nopagebreak stops it breaking before the list.

-
If I insert \widowpenalty=-5000 between pages 3/4 (at the place you suggest), it remains active for the pagebreak between 5/6 as well. Is this good? Then I might as well set it once, in the preamble, or are there any adverse effects to beware of? –  Lover of Structure Jan 23 '13 at 0:34
oops no best to set it back again it encourages the last line of a paragraph to be widowed (pushed over to the next page) which isn't usually what you want. You could use {\widowpenalty=-5000 \nopagebreak\par} except as I noted above that defeats latex list code checking for an in-par list, so probably best to set it back after (both) \begin{itemize} and \end{itemize} –  David Carlisle Jan 23 '13 at 0:42
Actually, {\widowpenalty=-5000 \nopagebreak\par} seems like the perfect solution for my case, because if I don't want to use "keep together" functionality, I just don't use this (and use an empty line in before the list instead). Correct me if I'm wrong. I'll try it out a little later and will report back. –  Lover of Structure Jan 23 '13 at 2:16
latex puts on more vertical space (above and below) usually if there is a par before the list (\partopsep) see \documentclass[twocolumn]{article} \raggedbottom \begin{document} \hrule a \begin{enumerate}\item b\end{enumerate} c \hrule \pagebreak \hrule a \begin{enumerate}\item b\end{enumerate} c \hrule \end{document} –  David Carlisle Jan 23 '13 at 2:38
Oh in that case I don't want the \par. So I basically need \widowpenalty=-5000 \nopagebreak before and then \widowpenalty=previousvalue both after \begin{itemize} and \end{itemize}, correct? Is there a trivial way of storing previousvalue just before \widowpenalty=-5000 \nopagebreak? Then I'll just define macros for both <save \widowpenalty somehow in previousvalue> \widowpenalty=-5000 \nopagebreak and \widowpenalty=previousvalue. –  Lover of Structure Jan 23 '13 at 7:04