# How do I combine addvspace and nobreak?

\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{}(ends here)

With breaks:
\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

\clearpage
\lipsum[1-4]
\par{}Here's a block
\subsection*{Here's a second block}
\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

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