\\* and \\ \nopagebreak not working as expected
Never use \\
at the end of a paragraph.
If you need to add vertical space use \vspace
or a pre-defined space such as \bigskip
.
In the document below TeX chooses the page break at the extra space, adding \nopagebreak
at the point indicated prevents that choice so forcing TeX to take a different page break here it breaks the preceding paragraph taking one line over to the next page followed by the big skip.
\documentclass[a5paper]{article}
\begin{document}
\def\z{\stepcounter{enumi}\roman{enumi}\ one two three four five six seven eight nine ten. }
\def\zz{\z\z\z\z\z\z\z Black white blue red green. \z\z}
AAA \zz\zz
BBB \zz\z\z
line a line a line a line a line a line a line a line a line a line a line a
line b line b line b line b line b line b line b line b line b line b
line c line c line c line c line c line c line c line c line c line c
%\nopagebreak
\bigskip
CCC \zz
DDD \zz
\end{document}
Related videos on Youtube
Nero gris
Updated on December 07, 2020Comments
-
Nero gris almost 3 years
I need an empty line between two paragraphs and so as usual I end one of them with
\\
. However that paragraph was at the bottom of a page so the empty line is difficult to see if you don't know to look for it. Searching on line I found two possible solutions\\*
and\\ \nopagebreak
however both of these produce the same behavior.So, I either need to break the page sooner, or have something indicating that a break, other than a page break, has also occurred. However, since the text above it may change (and there is a lot text above it) I don't want to make this a special case. Meaning I don't want to manually force a break in the middle of the paragraph myself, if that is the solution, but rather I want LaTeX to do that.
-
Ulrike Fischer almost 6 yearsDon't end paragraphs with \\. This only give underfull box warnings. If you need space between paragraphs use \vspace.
-
David Carlisle almost 6 yearsplacing
\\
at the end of a paragraph will always give bad spacing (tex warns you about badness 10000, which is the maximum value it assigns to any bad box)
-
-
Nero gris almost 6 yearsThanks, that did it. I needed the \nopagebreak first. Also, thanks for pointing out the problem with \\. I've just been ignoring the underfull box warnings since they didn't result in any discernible issues. I made a macro command for \nopagebreak\vspace{\baselineskip} which has the same desired result without the errors or not working the way I think it should.