How do I prevent a line from appearing by itself:
Orphan: at the bottom of the page, or
Widow: at the top of the page?
As Brent points out, you cannot always do this. The best you can do is to tell TeX that it's infinitely bad for these to appear:
\widowpenalty10000
\clubpenalty10000
One thing to keep in mind is that when presented with multiple infinitely bad options, TeX just picks one of them so you can still get widows or orphans.
\widowpenalty=10000
. It didn't work then. Thanks! :)
=
in the assignment, but it doesn't hurt. \widowpenalty=10000
and \widowpenalty 10000
are the same.
You can now use the nowidow
package to make this task easier:
\usepackage[all]{nowidow}
nowindow.sty
, I don't seem to have it in my standard (Mac) TeX install... Thanks
Commented
Oct 25, 2013 at 9:03
nowidow
, not nowindow
.
\noclub
and \setnoclub
commands).
The Memoir manual, in section 3.5 "Sloppybottom" discusses this in some detail, which I won't reproduce here.
Be prepared even to re-word in the most intractable cases.
Update:
I think the specific commands like \enlargethispage
and \sloppybottom
are exclusively for the memoir package, but here's a snippet extracted from the aforementioned that you may care to adjust (you can see the extensive comments in the original):
\clubpenalty=9996
\widowpenalty=9999
\brokenpenalty=4991
\predisplaypenalty=10000
\postdisplaypenalty=1549
\displaywidowpenalty=1602
Personally, I tend to avoid this TinXering with Plain TeX internals; although I don't know how to do it specifically for newlfm,
I'd probably opt for adjusting the textheight on a case-by-case basis, as a final tidy-up before publishing.
\sloppybottom
is indeed memoir
-specific (\raggedbottom
is the comparable "plain" command), \enlargethispage
is defined in base latex, so should be usable with any document class.
Commented
Sep 27, 2011 at 13:27
In order to make a club or widow line disappear, you can use solutions such as rewording or reordering, changing fonts or margins, or commands like \enlargethispage{1cm}
or \enlargethispage*{1cm}
(the latter “also shrinks any vertical white space on the page as much as possible, so as to fit the maximum amount of text on the page”, according to usrguide). But let's present less invasive possibilities here.
TeX's algorithm for breaking a paragraph into lines offers a few knobs that can be very useful during the final phase of document preparation, because they can make paragraphs shorter or longer without any rewording, retaining good visual aspect especially if the paragraphs in question are long (if a paragraph is long enough, it's usually very easy for TeX to make it one line shorter or longer than what it would normally be, because there are many spaces that can be stretched or shrunk: at the very least, the interword spaces).
First, the integer parameter \linepenalty
is used to compute the “demerits” of each line of a paragraph.1 Increasing \linepenalty
makes every additional line in a paragraph more “expensive”, and therefore leads to shorter paragraphs. The value that matters is the value when the paragraph ends. Plain TeX and LaTeX set \linepenalty=10
.2
There is another useful integer parameter that gives control over the number of lines in a paragraph (without changing the line length, paragraph shape, font, etc.): this parameter is called \looseness
.3
If you say \looseness=<number>
for a paragraph, TeX will try to make it <number>
lines longer than what would have been done otherwise, without exceeding the current \tolerance
. <number>
may be negative (e.g., \looseness=-1
), in which case TeX will try to make the paragraph shorter. Here is an example:
\documentclass{article}
\usepackage{lipsum}
\begin{document}
\looseness=-1 % Make the next paragraph one line shorter than normal.
% Note the space token after -1. Otherwise,
% you can write \looseness=-1\relax.
\lipsum[1-5]
\lipsum[6][1-2]
\end{document}
Without the \looseness
change, the above document has two pages with only three words on the second page:
But simply setting \looseness
as done in the above example allows the document to fit on a single page without changing margins or doing other ugly things:
Note that this works because the first paragraph of the document whithout any \looseness
change is easy to shrink (its last line contains only one word, and the paragraph is not ridiculously short). When the change asked via \looseness
is not possible without exceeding the \tolerance
, \looseness
has no effect. In other words, you can't take a two lines paragraph and expect TeX to shrink it by two lines by setting \looseness=-2
!
The value of \looseness
that matters is the one it has at the end of the paragraph you want to modify. \looseness
is reset to zero at the same time as \hangindent
, \hangafter
, and \parshape
are reset to their normal values, which is “at the end of every paragraph, and (by local definitions) whenever it enters internal vertical mode.”4
Therefore, the \looseness=-1
in the above example affects only the first of the five paragraphs produced by \lipsum[1-5]
. There is no need to do this assignment inside a group.
If you want to make a paragraph as short as possible, you can try settings such as \looseness=-1000
or \linepenalty=100
, the latter being less expensive in terms of computing time.5
The TeXbook also mentions a trick to spread some looseness among several paragraphs.6 Suppose that you want to make one of three paragraphs looser, but you don’t want to choose which one it will be. The trick is to combine the three paragraphs into a single one as far as TeX is concerned, and make it just look as if they were three paragraphs. To do this, simply end the first two paragraphs with a command named, e.g., \fakepar
, and defined as follows:
\newcommand*{\fakepar}{%
\hfil\vadjust{\vskip\parskip}\break\indent
}
This can be used in the lipsum example by doing \let\endgraf\fakepar
like this:
\documentclass{article}
\usepackage{lipsum}
\newcommand*{\fakepar}{%
% cf. TeXbook exercise 14.23, p. 315
\hfil\vadjust{\vskip\parskip}\break\indent
}
\begin{document}
{
% Try to make one of the following five paragraphs one line shorter
\looseness=-1
\let\endgraf\fakepar
\lipsum[1-5] % \fakepar is used *between* the paragraphs
}% Now comes the \par that terminates paragraph 5 of the \lipsum[1-5]
\lipsum[6][1-2]
\end{document}
I'm not quite sure why \let\par\fakepar
doesn't work in this case, because according to the lipsum
package documentation, it seems to me that \lipsum[1-5]
uses \par
separators by default between the paragraphs. If anyone has an idea, please edit this.
What we discussed in the previous section can change the line breaks in a paragraph, and thus the number of lines occupied by a given paragraph (you can increase or decrease it, according to your needs and the possibilities offered by the particular paragraph). In order to avoid club or widow lines, another possibility is to work on page breaks without changing the appearance of any paragraph (apart from the fact that page breaks can split paragraphs), in particular without modifying the number of lines of any paragraph.
This can work if your pages have enough vertical space that can stretch or shrink. \parskip
is often a good friend for this, because both plain TeX and LaTeX set \parskip=0pt plus 1pt
, which gives one point of stretchability between any two paragraphs. List environments (itemize
, enumerate
, description
...) and sectioning commands (\section
, \subsection
, etc.) are also good contributors to vertical stretchability and shrinkability in pages7, and so are display math formulas (\[ ... \]
, the equation
environment, LaTeX's displaymath
and amsmath's equation*
environments).8
But if despite all these opportunities for vertical stretching and shrinking, you still have page breaks that produce a club or a widow line, it is possible to play with penalties in order to discourage page breaks in specific conditions. In particular, you might want to increase the value of \clubpenalty
(to avoid page breaks after the first line of a paragraph) or \widowpenalty
(to avoid page breaks before the last line of a paragraph).9 But:
LaTeX adds a layer in this area as compared to plain TeX; see the discussion about \@clubpenalty
in this message from egreg;
be aware that there will be a price to pay, otherwise TeX wouldn't have produced such unpleasant page breaks in the first place!
Things to keep in mind:
\linepenalty
and \looseness
influence how lines are broken inside a paragraph;
\clubpenalty
and \widowpenalty
help TeX decide after which line it is going to break a page, but don't affect the appearance of paragraphs—apart from the particular lines after which a paragraph may possibly be split, between a page and the one that follows.
LaTeX often resets \clubpenalty
to the value saved in \@clubpenalty
. The value of \@clubpenalty
is initialized from \clubpenalty
at the beginning of the LaTeX run (see ltfiles.dtx
); \clubpenalty
is also copied to \@clubpenalty
as part of the work done by \begin{document}
. Then, during further document processing, \clubpenalty
may be temporarily set to values such as 10000 by code from the LaTeX kernel, then automatically reset to the value stored in \@clubpenalty
(see the definition of \@afterheading
, a macro that is called by sectioning commands). Therefore, don't expect a change to the TeX parameter \clubpenalty
to last in a LaTeX document, unless you do it in the preamble. If you want to perform a long-lasting change for this parameter after the preamble, better affect both \clubpenalty
and \@clubpenalty
.
Footnotes
\documentclass
optional argument (10pt
, 11pt
and 12pt
respectively).\abovedisplayskip
, \abovedisplayshortskip
, \belowdisplayskip
and \belowdisplayshortskip
in the aforementioned size10.clo, size11.clo and size12.clo files.This FAQ answer gives some tips, including enlarging/reducing the (double-)page, setting the paragraph tighter, using \raggedbottom
(for which, see also this FAQ answer which discusses putting some stretch in the \topskip
).
I'd been using the 10000 penalty for years (since 2005). This morning I learned the default was 150, and 500 was pretty aggressive. When I dropped from 10000 to 500, the widow/orphan lines went up (from 2 to 3). When I left it at default, the typical widow/orphan lines went toward 4...and new sections were more frequently shoved to the next page.
Now it looks the way I wanted to.
Sometimes, even with all of the suggestions above, you end up with an odd looking page, something without an apparent solution if you are not at the liberty of rewording the text. For those instances, I have developed a simple command, Kern
, which allows to increase or decrease character tracking by fractions of a point
.
% Kern
% #1 kerning amount
% #2 text
\newcommand{\Kern}[2]{\addfontfeature{LetterSpace=#1}#2\addfontfeature{LetterSpace=0}\null}%
So if you have some text, you would decrease tracking thus:
\Kern{-1.0}{Sometimes, even with all of the suggestions above,
you end up with an odd looking page, something without an apparent
solution if you are not at the liberty of rewording the text.}
And, conversely, increase tracking thus:
\Kern{+1.0}{Sometimes, even with all of the suggestions above,
you end up with an odd looking page, something without an apparent
solution if you are not at the liberty of rewording the text.}
Following up Nico's comment, this solution works with XeLaTeX
and LuaLaTex
only, and you need to have fontspec
loaded.
fontspec
package is loaded. It would also be helpful if you gave a couple of examples of how to use \Kern{...}{...}
.
\usepackage[all]{nowidow}
as ℝaphink suggested