2

I want to prevent a certain line from being the last line on a page. If necessary, I want whitespace to get automatically inserted before it so that it gets pushed to the beginning of the next page.

Normally, using \nopagebreak would solve this. However, I also want that line to be pushed to the beginning of the next page, even if there is a blank line after it (from the \ or \vspace{\baselineskip} command) on the first page. (And unfortunately, \nopagebreak doesn't seem to work for this...)

\documentclass{article}

\begin{document}
Text.

\vspace{41\baselineskip}
More text.

\vspace{\baselineskip}
\textbf{I don't want this line to be the last line of the page.}

\vspace{\baselineskip}
\nobreak
Even more text.
\end{document}
7
  • 1
    With the needspace package, just issue \needspace{\baselineskip} before that line.
    – Werner
    Commented Nov 21, 2013 at 0:21
  • @Werner Thanks! However, that doesn't work if the line is also preceded by a \ (as it happens to be in my document). Commented Nov 21, 2013 at 0:24
  • 1
    why is there a line with \ whatever it is intended to do it can't be the right way to do it, it makes something that looks a bit like a vertical space but the behaviour at page break is all wrong. Commented Nov 21, 2013 at 0:29
  • 1
    @jamaicanworm: If I use your example and add \needspace{\baselineskip} after \vspace{\baselineskip}, then I obtain the desired result (the text is flushed to the subsequent page).
    – Werner
    Commented Nov 21, 2013 at 0:50
  • 1
    If you add the showframe package to your preamble and keep \vspace{42\baselineskip}, you'll see that your "text that should be moved" is not really at the bottom. As such, there's actually more than a \baselineskip between the top of the line and the bottom of the text block (the reason why \needspace{\baselineskip} doesn't work). You could increase this "needed space" using something like \needspace{1.5\baselineskip}. I'm still confused with your example/MWE, since adding \needspace{\baselineskip} is sufficient in both cases to flush the text.
    – Werner
    Commented Nov 21, 2013 at 1:02

1 Answer 1

3

The markup in the MWE is very odd but as a box never breaks one possibility would be

\noindent
\begin{minipage}{\textwidth}
More text.

\textbf{I don't want this line to be the last line of the page.}

even more text
\end{minipage}

but that freezes the vertical space so it may not match flexible space on the same page. Depending on your real use case it may be OK though.

If you just want to manually adjust a particular page an alternative to pushing text over is to change the page size with

\enlargethispage{\baselineskip}

to fit in an extra line.

2
  • I don't want to alter the page size at all. Also, wouldn't the minipage push the More text. line onto the next page as well? Commented Nov 21, 2013 at 0:40
  • 1
    @jamaicanworm I wasn't sure where you wanted to prevent the break, the question title says prevent a line from being first on page, and the example asks to prevent a line from being bottom of page (which isn't necessarily contradictory if you are talking of different lines) but anyway just box up whatever region shouldn't break. Commented Nov 21, 2013 at 1:06

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .