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.)
Best Answer
Let's look at what we get when we add
\showoutput
. I just show the diagnostic messages relative to the first pair of lines:It's quite clear what happens: the command
\\*
does\vadjust{\penalty10000}
and this\vadjust
item find its way after the line containingline 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.