5

Consider this texample

\documentclass{report}
\begin{document}
Some text

\medskip
\textbf{Mini title}
\medskip

\nopagebreak
Some more text
\end{document}

How can I avoid a page break between "Mini title" and "Some more text". I am exploring \nopagebreak to this end but to no avail?

1
  • 5
    why are you using \textbf font change not a propper heading such as \section*{mini title} ? latex never allows a page break after section heads. Commented Feb 27, 2019 at 13:26

3 Answers 3

5

I copied the \medbreak command from LaTeX and made a \mednobreak. It does a \nopagebreak and a \medskip. It will attach the first line of the following paragraph to the \textbf{Mini title}. Comment the line marked to see the effect.

\documentclass{report}
\usepackage{lipsum}
\def\mednobreak{\par\ifdim\lastskip<\medskipamount
  \removelastskip\nopagebreak\medskip\fi}
\begin{document}
\lipsum[1-4]
\lipsum[2]

another line % comment to see difference

\medskip
\textbf{Mini title}
\mednobreak
\lipsum[1]
\end{document}
5

Avoid using explicit font change commands.

if you use a section heading command the markup is more flexible and LaTeX automatically takes care of not allowing a page break after the heading

\documentclass{report}
\begin{document}
Some text

\vspace{40\baselineskip}% heading and text stay on this page
%\vspace{41\baselineskip}% heading and text go to next page

Some text

\subsection*{Mini title}

Some more text
\end{document}
3

I suggest you load the needspace package and issue the directive

\Needspace*{3\baselineskip}

immediately before the first \medskip directive.


A full MWE (minimum working example):

\documentclass{report}
\usepackage{needspace}
\begin{document}
\dots 

Some text

\Needspace*{3\baselineskip}
\medskip
\textbf{Mini title}
\medskip

Some more text
\end{document}

You must log in to answer this question.

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