TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

\nopagebreak makes it infinitely bad to break at that point. So TeX will not break at that node However it is possible that it breaks at that point visually for example

 blah blah

 \nopagebreak
 \hrule height 0pt
 \pagebreak[2]


 blah blah

Then TeX will not break above the invisible rule, but may break after the invisible rule. So it may seem that adding \nopagebreak has not worked.

In complicated macros like section headings that are adding multiple penalties and spaces, each of which separately introduces a potential breakpoint it can be quite hard to prevent page breaking with a single \nopagebreak but the details depend on the exact details of the macro, and where it is inserting vertical space and penalties.


In answer to the question in comments, usually a single \nopagebreak will prevent a page break as long as there is another feasible break point on that page, for example if you uncomment the \pagebreak here The break at that point is avoided by taking two extra lines over to the next page.

\documentclass{article}

\setlength\textwidth{5cm}
\setlength\textheight{16cm}
\begin{document}

\section{zzz}
abc\par one two three four one two three four one two three four
abc\par one two three four one two three four one two three four
abc\par one two three four one two three four one two three four
abc\par one two three four one two three four one two three four
abc\par one two three four one two three four one two three four
abc\par one two three four one two three four one two three four

\section{zzz}
abc\par one two three four one two three four one two three four
abc\par one two three four one two three four one two three four
abc\par one two three four one two three four one two three four
abc\par one two three four one two three four one two three four
abc\par one two three four one two three four one two three four
abc\par one two three four one two three four one two three four

\section{zzz}
abc\par one two three four one two three four one two three four
abc\par%\nopagebreak
one two three four one two three four one two three four
abc\par one two three four one two three four one two three four
abc\par one two three four one two three four one two three four
abc\par one two three four one two three four one two three four
abc\par one two three four one two three four one two three four


\end{document}
share|improve this answer
1  
Can you give an example where the output is visually affected by a single \nopagebreak command? – Ari Brodsky Sep 2 '14 at 1:48
    
@AriBrodsky year and a half late sorry, just noticed your comment and updated the answer. – David Carlisle Jan 13 at 15:56

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.