# How to avoid page-breaks inside paragraphs?

I would like to know if there is any global command that would prevent any page-breaks inside paragraphs. I'd rather have the whole paragraph on the next page instead of having it cut in the middle. I tried the \nopagebreak command but it doesn't do the trick. Any idea?

-
Welcome to TeX.sx! A tip: you can use backticks ` to mark your inline code as I did in my edit. –  egreg Jun 30 '11 at 13:34
I took the liberty to adjust the title and text slightly to highlight the fact that you are talking about in-paragraph page breaks. There will be of course some page-breaks between them. We had already a question about really disabling page breaks altogether as well. Don't forget to accept egreg's answer if it helped you. –  Martin Scharrer Jun 30 '11 at 15:07
BTW: \nopagebreak is to avoid a page break in the current line, i.e. the line it is used in. It has no global effect. –  Martin Scharrer Jun 30 '11 at 15:50

You can inhibit page breaks in the middle of paragraphs by saying in you preamble

\widowpenalties 1 10000
\raggedbottom

Without \raggedbottom (that the article class does automatically) the pages would be awful.

The primitive \widowpenalties is an extension to the original TeX program, present in e-TeX based engines (pdftex, xetex and luatex). It generalizes the \widowpenalty parameter of TeX, which contains the penalty inserted before the last line of a paragraph to help controlling widow lines.

The general syntax of \widowpenalties is

\widowpenalties n p1 p2 ... pn

where n is a non-negative integer and p1, p2, ..., pn are the values of the penalties inserted before the various lines of a paragraph starting from the bottom. If the paragraph has more than n+1 lines, the last value is repeated. So the following settings are equivalent

\widowpenalty 1000
\widowpenalties 2 1000 0

If one wants to reset the array to zero (and TeX will use the standard parameter \widowpenalty), it's sufficient to say

\widowpenalties 0

or set the array in a group, of course. It follows from the stated rules that

\widowpenalties 1 10000

will insert a penalty of 10000 (no break) between all lines in every paragraph, thus prohibiting mid-paragraph page breaks.

The array \clubpenalties is similar, but it works from the top of the paragraph down. So an alternative solution is

\clubpenalties 1 10000

Of course, as lockstep points out, there's a "pure TeX" solution:

\interlinepenalty 10000

but \widowpenalties is more powerful than this. For example, if we need to break a paragraph before the third line from the bottom, we can say

... here the paragraph ends.
{\widowpenalties 4 10000 10000 -10000 0 \brokenpenalty 0 \par}

which is easier than the TeX method of putting \vadjust{\break} somewhere in the line that precedes the desired break; \brokenpenalty 0 is needed because otherwise the penalty inserted would be greater than -10000.

Since TeX uses the parameter values which are current at the moment a \par is sensed, it will use the stated ones, resetting them at group end. The group is (almost) necessary, because the setting of \widowpenalties is permanent, that is not like \hangindent, \hangafter or \parshape that are automatically reset as part of the action of \par.

## Notes

TeX always uses the values of the parameters that are current at the time of \par for deciding how to break the paragraph into lines and creating the vertical list to be fed to the "recent contributions", no matter how many times they are changed during the paragraph itself: \leftskip, \rightskip, \hangindent, \hangafter, \parshape, \pretolerance, \tolerance, \emergencystretch (and probably others, there are so many). After it has decided the line breaks, it assesses interline penalties and demerits to be transferred to the enclosing vertical list and contributes the boxes it has built inserting also the interline glue based on the values of \baselineskip, \lineskip and \lineskiplimits (also these are among the "unique value" parameters).

Thus one can change the applicable value of, say, \widowpenalties at the start, in the middle or just before the end of the paragraph and only the last setting will be taken into account. One might solve the "break before the third to last line" by setting \widowpenalties at the beginning, enclosing the whole paragraph in a group. But the trick of setting it in a group avoids this need. It has some "pros and cons": the pros are that we don't need to reset the changed values; the cons are that \hangindent, \hangafter and \parshape are not effectively reset, because the end of the group annihilates the resetting done by \par! This may be a problem in a LaTeX list which uses \parshape; it may be also a problem in some special places where LaTeX redefines \par in such a way that it redefines itself to a "normal \par".

-
Thanks! It worked like a charm! –  themetis Jun 30 '11 at 13:40
Could you maybe explain what the two numbers following \widowpenalty refer to? –  Seamus Jun 30 '11 at 15:07
@Seamus: I just found it in the eTeX manual: it's an array specification, where 1 is the number of entries in 10000 is that one entry. I wonder what the benefit over \widowpenalty=10000 is? –  Martin Scharrer Jun 30 '11 at 15:19
@Martin: see edit; there is a benefit, as you can see. The key is in "repeating the last value if necessary". –  egreg Jun 30 '11 at 15:26
@egreg: Thanks for the explanation (+1). So \widowpenalties 1 10000 states to use a page break penalty of 10000 for every line of the paragraph, right? –  Martin Scharrer Jun 30 '11 at 15:31

The "original TeX" solution: \interlinepenalty 10000.

-

I have used the nowidow package by Raphael Pinson with some success.

\usepackage[<options>]{nowidow}

I use: \usepackage[defaultlines=4,all]{nowidow}

A value of 4 works for me because I can tolerate some breaks in very large paragraphs.

I think you can be pretty sure of banning all page breaks in a paragraph if you set the value of defaultlines to something quite high.

-
Welcome to TeX.SX! –  Adam Liter Feb 25 '14 at 20:33
Thanks for the welcome. I usually never post because almost everything seems answered. Generally, I come here looking for answers. I noticed this particular question because I was looking for an answer to this question, or something close enough. The answers here did not quite work for my particular needs, so I looked elsewhere on the web and found the nowidow package. I came back here not entirely out of altruism but also to "archive" the solution for myself. I can be forgetful, but I know that I will be back here whenever I need a solution. –  Hína Kemenduro Feb 25 '14 at 23:21