# \nopagebreak after a center environment

I have the following code for a Theater play. Sometime the page breaks just after the name of a character. I would like to avoid that. I would be good if I could do it only by modifying the command \character since the play is 200 pages long with many different characters. I tried to use \nopagebreak but I was not successful. What can I do in order to never have the name of a character on the bottom of a page?

\documentclass[a5paper]{book}
\usepackage{geometry}
\usepackage{lipsum}

\newcommand{\character}[1]{
\begin{center}
\textsc{#1}
\end{center}}

\begin{document}
\character{Alice} \lipsum[2]
\character{Bob} \lipsum[2]
\character{Charles} \lipsum[2]
\character{David} \lipsum[2]
\character{Edmond} \lipsum[2]
\character{Francis} \lipsum[2]
\end{document}


latex headings include code to prevent a page break until a couple of lines after a heading, so it best to define this as an unnumbered heading:

\documentclass[a5paper]{book}
\usepackage{geometry}
\usepackage{lipsum}

\makeatletter
\newcommand{\character}{%
\@startsection {section}{1}{\z@}%
{-3.5ex \@plus -1ex \@minus -.2ex}%
{2.3ex \@plus.2ex}%
{\normalfont\scshape\centering}*}
\makeatother

\begin{document}
\character{Alice} \lipsum[2]
\character{Bob} \lipsum[2]
\character{Charles} \lipsum[2]%aaa\\bb
\character{David} \lipsum[2]
\character{Edmond} \lipsum[2]
\character{Francis} \lipsum[2]
\end{document}


Add \vfil before the center environment in your command:

\documentclass[a5paper]{book}
\usepackage{geometry}
\usepackage{lipsum}

\newcommand{\character}[1]{%
\vfil
\begin{center}
\textsc{#1}
\end{center}
}

\begin{document}
\character{Alice} \lipsum[2]
\character{Bob} \lipsum[2]
\character{Charles} \lipsum[2]
\character{David} \lipsum[2]
\character{Edmond} \lipsum[2]
\character{Francis} \lipsum[2]
\end{document}


## Output

You can also wrap the character name and his words together into a \vbox to prevent that they get separated. But, for that you would need to change every single call of the character macro. (I added it just for completeness for future users who are interested in typesetting theater plays and encounter a similar problem.)

\documentclass[a5paper]{book}
\usepackage{geometry}
\usepackage{lipsum}

\newcommand{\character}[2]{%
\par\vspace{1em}
\vbox{%
\par\hfil\textsc{#1}\hfil
\par\vspace{1em}
\par#2
}
}

\begin{document}
\character{Alice}{\lipsum[2]}
\character{Bob}{\lipsum[2]}
\character{Charles}{\lipsum[2]}
\character{David}{\lipsum[2]}
\character{Edmond}{\lipsum[2]}
\character{Francis}{\lipsum[2]}
\end{document}


Note: The output is almost as above.

• \vfill does not prevent a page break after the heading (try \character{Charles} \lipsum[2]aaa\\bb and it breaks after charles, Jul 5, 2015 at 0:36
• Thanks ruben for the advices. These are already better solutions that what I managed to do. But the point of David about \vfill is right. And the other solution with a vbox is also problematic when a character has a long monologue. Then it creates a huge vertical box that cannot be cut. Jul 5, 2015 at 12:16