3

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}
4

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}
1

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

output

Addendum

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.

  • 1
    \vfill does not prevent a page break after the heading (try \character{Charles} \lipsum[2]aaa\\bb and it breaks after charles, – David Carlisle Jul 5 '15 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. – Gilles Bonnet Jul 5 '15 at 12:16

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.