# How can I avoid widows and orphans after displayed equations?

Edit: The original title of this question was "How can I avoid widows and orphans with the geometry package?" However, as egreg pointed out, the geometry package was not the cause of the problem. So, I have corrected the title.

I am writing my dissertation. My university specifies the page margins and absolutely forbids widows and orphans. To avoid the latter, I have set both clubpenalty and widowpenalty to 10000. I am using the geometry package to set the margins. As the following example shows (or, at least, does when I run pdfLaTeX), this can create widows and orphans. I've tried using geometry with various options, such as including or ignoring this or that. How can I keep to the required margins without creating widows and orphans?

\documentclass{article}
\usepackage[lmargin=1.5in,rmargin=1.0in,tmargin=1.0in,bmargin=1in]{geometry}
\usepackage{lipsum}

\widowpenalty = 10000
\clubpenalty = 10000

\begin{document}

\lipsum

This text is boring and repetitive.

This text is boring and repetitive.

This text is boring and repetitive.  However, it is easy to see that
$x^n + y^n = z^n$
has no solutions for $n \geq 3$.  This text is boring and repetitive.  This text is boring and repetitive.

This text is boring and repetitive.

This text is boring and repetitive.

\end{document}

-

The displayed equation is not counted as part of the paragraph in the context of widows and orphans. You can forbid a page break after the displayed equation by setting

\postdisplaypenalty=10000

-
Thanks! I ended up needing a \postdisplaypenalty of 10000, and it doesn't look pretty, but it meets the requirements. –  Andrew Uzzell Mar 29 '12 at 22:21

The geometry package has nothing to do with widows and orphans. In your example a widow is created because of the display. Some remedy can be applied, but only when the text of your document is in final form.

For example, adding a line to an "almost full" long paragraph may avoid an orphan or a widow

Some long paragraph that ends almost flush right.\looseness=1


or conversely trying to shorten a long paragraph that doesn't quite fill the last line

Some long paragraph that doesn't fill the last line.\looseness=-1


Other known tricks are adding some words to a paragraph, or cutting some.

The correct parameter to set for "avoiding" orphans is

\makeatletter
\@clubpenalty=10000
\makeatother
\clubpenalty=10000 % initial value


because LaTeX uses \@clubpenalty to reinstate \clubpenalty after it has changed it to 10000 in some occasions.

A final comment: your institution forbids club and widow lines, but forces you to use a page format that's simply awful and unreadable. :(

-
Thank you for the answer and for the correction. I assumed that geometry was causing the problem because the document did not have any widows or orphans before I added that package. That I can only fix this when my document is otherwise finalized is not, of course, what I hoped to hear, but it's very good to know. –  Andrew Uzzell Mar 29 '12 at 21:26

Something has to give....

If you don't want TeX to break there you have to let it break somewhere else. There isn't enough stretch on the page to pad out if it breaks anywhere else. the following settings work on your example, but...

\widowpenalty = 10000
\clubpenalty = 10000
\postdisplaypenalty =100

\parskip0pt plus 15pt

-

Besides all the (very good!) answers above, probably the microtype package might help as well. Though it does require lots of tweaking now and then. But it would allow you flexibility on the sub-letter level.

E.g., if there is an orphan, for the preceeding lines you might ask TeX/microtype to squeeze the letters together a bit more so that the orphan is solved.

But then, you really (REALLY) shouldn't start any of this tweaking before you have finished the entire document. Indeed, the addition of one line at the beginning of a chapter might require you to retweak all orphans and widows in that particular chapter.

-