1

\nobreak seems to break \addvspace, as shown by the example below. How can I prevent a page break before and after a space added by addvspace, without breaking addvspace?

\documentclass{article}
\setlength{\parindent}{0pt}

\begin{document}
No breaks:
\par{}\nobreak\addvspace{5em} \nobreak\addvspace{5em} \nobreak\addvspace{5em}
\par{}(ends here)

With breaks:
\par{}\addvspace{5em} \addvspace{5em} \addvspace{5em}
\par{}(ends here)
\end{document}

Here's is a more concrete example:

\documentclass{article}

\usepackage{lipsum}
\setlength{\parindent}{0pt}
\newcommand{\block}{\fbox{\begin{minipage}{\textwidth}\lipsum[1]\end{minipage}}}

\begin{document}
\clearpage
\lipsum[1-4]
\par{}Here's a block
\par\addvspace{4em}\nobreak\block % Does not work

\clearpage
\lipsum[1-4]
\par{}Here's a block
\par\nobreak\addvspace{4em}\block % Works, but…
\subsection*{Here's a second block}
\par\nobreak\addvspace{4em}\block % … addvspace behaves as vspace
\end{document}

In this example, I have a block of text (\block) preceded by a single sentence. I want to keep them together. Additionally, I want block to be visually separated from its surroundings, by a consistent amount of vertical space. I use addvspace before each \block to ensure this.

Unfortunately, \nobreak confuses vspace: the space following section titles is not combined with the space preceding blocks.

How can I ensure that \block is always preceded by 5em of vertical space, while preventing page breaks before blocks, and without adding spurious space between section titles and immediately following blocks?

  • not directly addressing your problem, but multiple consecutive instances of \addvspace aren't really going to add up to the expected total. the total will only be the largest value specified with either the \addvspaces or the vertical space already present at that point. \addvspace is an instruction to bring the total space to the specified value, not to accumulate it. – barbara beeton Sep 10 '16 at 1:59
  • @barbarabeeton Exactly: hence my question. This behaviour is what I expect, but the \nobreak call breaks it. – Clément Sep 10 '16 at 15:53
3

use \addpenalty which is similar to \addvspace, but for penalties.

\documentclass{article}

\usepackage{lipsum}
\setlength{\parindent}{0pt}
\newcommand{\block}{\fbox{\begin{minipage}{\textwidth}\lipsum[1]\end{minipage}}}

\begin{document}
\clearpage
\lipsum[1-4]
\par{}Here's a block
\par\addpenalty{10000}\addvspace{4em}\block  Does not work

\clearpage
\lipsum[1-4]
\par{}Here's a block
\par\addpenalty{10000}\addvspace{4em}\block % Works, but…
\subsection*{Here's a second block}
\par\addpenalty{10000}\addvspace{4em}\block % … addvspace behaves as vspace
\end{document}

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.