5

Sometimes \\* does not suffice to prevent a linebreak. Adding {\widowpenalty10000 \par} or {\clubpenalty10000 \par} helps if the separated line is paragraph-final and stranded at the top of a page ("widow") or paragraph-initial and stranded at the bottom of a page ("orphan").

Here is an example:

\documentclass{article}

\newcommand*{\twolines}{%
  line 1 \\*
  line 2 \par%
}
\newcommand*{\twolinesInseparable}{%
  line 1 \\*
  line 2 {\widowpenalty10000 \par}%
}

\begin{document}

\vspace*{32\baselineskip}
\twolines\twolines\twolines
\twolines\twolines\twolines
\twolines\twolines\twolines

\newpage

\vspace*{32\baselineskip}
\twolinesInseparable\twolinesInseparable\twolinesInseparable
\twolinesInseparable\twolinesInseparable\twolinesInseparable
\twolinesInseparable\twolinesInseparable\twolinesInseparable

\end{document}

In this code, the linebreak between pages 1 and 2 (\twolines) will split a 2-line chunk (despite the \\*), whereas this doesn't happen between pages 3 and 4 (\twolinesInseparable, which sets an "infinite" (10000) \widowpenalty).

Do these two parameters interact in a meaningful way for a 2-line paragraph?

(This is a theoretical question. I don't have a practical application right now other than the thought experiment of making sure that different macros that include a \widowpenalty or \clubpenalty don't conflict or create nonsensical or conflicting constraints.)

  • Well, first of all, these details are part of the last step of the editing process with LaTeX. So it is nonsense to worry about them when you have not even finished writing. However, when it comes to reviewing the final text comes, and fixing widows and orphans, and \clubpenalty \widowpenalty are necessary. However often requires making final adjustments in paragraphs where those errors still persist. You can use \linebreak and \newpage for that. And that is in my opinion and experience exactly what you'd have to use with a hypothetical paragraph of barely two lines. – Aradnix Dec 26 '13 at 1:53
  • 1
    why not use \samepage if you know that there will be only two lines, or, to go a bit further, no more than four lines? – barbara beeton Dec 26 '13 at 14:52
  • @Aradnix 1. I know that this is the idealized textbook procedure. In practice I include such penalties during the writing process because I often have short paragraphs of a certain type for which I know I don't want any pagebreaks. But I agree that \newpage is only for the very end in most situations. 2. Sometimes complicated text and formatting just don't follow any neat structural model. In those cases LaTeX can be useful because it gives you control, but that control requires work. – Lover of Structure Dec 26 '13 at 19:16
  • @barbarabeeton The UK TeX FAQ states that "if samepage does work, it is capable of leaving stuff jutting out at the bottom of the page". That statement cautioned me away from \samepage. – Lover of Structure Dec 26 '13 at 19:20
6

Let's look at what we get when we add \showoutput. I just show the diagnostic messages relative to the first pair of lines:

Completed box being shipped out [1]
\vbox(633.0+0.0)x407.0
.\glue 16.0
.\vbox(617.0+0.0)x345.0, shifted 62.0
..\vbox(12.0+0.0)x345.0, glue set 12.0fil
...\glue 0.0 plus 1.0fil
...\hbox(0.0+0.0)x345.0
..\glue 25.0
..\glue(\lineskip) 0.0
..\vbox(550.0+0.0)x345.0
...\write-{}
...\glue(\topskip) 10.0
...\rule(0.0+0.0)x*
...\penalty 10000
...\glue 384.0
...\glue 0.0
...\glue(\parskip) 0.0 plus 1.0
...\glue(\baselineskip) 5.05556
...\hbox(6.94444+0.0)x345.0, glue set 306.11107fil
....\hbox(0.0+0.0)x15.0
....\OT1/cmr/m/n/10 l
....\OT1/cmr/m/n/10 i
....\OT1/cmr/m/n/10 n
....\OT1/cmr/m/n/10 e
....\glue 3.33333 plus 1.66666 minus 1.11111
....\OT1/cmr/m/n/10 1
....\penalty 10000
....\glue 0.0 plus 1.0fil
....\penalty -10000
....\glue(\rightskip) 0.0
....\glue(\rightskip) 0.0
...\penalty 10000
...\penalty 300
...\glue(\baselineskip) 5.05556
...\hbox(6.94444+0.0)x345.0, glue set 321.11107fil
....\OT1/cmr/m/n/10 l
....\OT1/cmr/m/n/10 i
....\OT1/cmr/m/n/10 n
....\OT1/cmr/m/n/10 e
....\glue 3.33333 plus 1.66666 minus 1.11111
....\OT1/cmr/m/n/10 2
....\penalty 10000
....\glue(\parfillskip) 0.0 plus 1.0fil
....\glue(\rightskip) 0.0
...\glue(\parskip) 0.0 plus 1.0
...\glue(\baselineskip) 5.05556

It's quite clear what happens: the command \\* does \vadjust{\penalty10000} and this \vadjust item find its way after the line containing line 1. But also the normal penalty pertaining to the paragraphs are added. In this case, the sum of \clubpenalty and \widowpenalty is inserted, resulting in \penalty300. Any penalty in the outer vertical list is a feasible page break point, and TeX can and does choose it in the seventh two line pair.

What does this mean? Simply that \\* should not be used in a paragraph for inhibiting a page break. In general \\ should not be used for breaking a line, to tell the complete truth.

  • If I understand this correctly, the answer to my actual question is that the sum of \clubpenalty and \widowpenalty is used. – Lover of Structure Jan 4 '14 at 3:00
  • 1
    @LoverofStructure Yes: when two “automatic” penalties apply, TeX inserts their sum (normalizing in the [-10000,10000] interval). – egreg Jan 4 '14 at 10:02

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.