2

I have in my document a custom sectioning command defined like this:

\newcommand{\newtitle}[4]{% \newtitle{<Title>}{<Author>}{<Date>}{<miscellaneous indications>}
  \vspace{2em}
    \begin{center}
      \textbf{\LARGE #1}\nopagebreak[4]\vspace{1em}\nopagebreak[4]\\\nopagebreak[4]
%
      \nopagebreak[4]\Large #2\nopagebreak[4]\vspace{0.5em}\nopagebreak[4]\\\nopagebreak
%
      \ifx&#3&%
      \else%
      \nopagebreak[4]#3\nopagebreak[4]\\\nopagebreak[4]%
      \fi%
% 
      \ifx&#4&%
      \else%
      \nopagebreak[4]\vspace{0.5em}\nopagebreak[4]
%
      \nopagebreak[4]\footnotesize\emph{#4}\nopagebreak[4]%
      \fi%
    \nopagebreak[4]\end{center}\nopagebreak[4]}

So, the code is pretty weired with this so much \nopagebreak it’s just because this multi-line style title should absolutely never be breaked.

The problem, is not really internal to the title but with the text who follow the \newtitle command. As I said, is a sectioning command, then it shouldn’t be breaked but it also always be in the same page than, at least two or tree following lines unless it will be a widow title.

As example, in the following MWE:

\documentclass[a4paper,12pt]{article}


\newcommand{\newtitle}[4]{% \newtitle{<Title>}{<Author>}{<Date>}{<miscellaneous indications>}
  \vspace{2em}
    \begin{center}
      \textbf{\LARGE #1}\nopagebreak[4]\vspace{1em}\nopagebreak[4]\\\nopagebreak[4]
%
      \nopagebreak[4]\Large #2\nopagebreak[4]\vspace{0.5em}\nopagebreak[4]\\\nopagebreak
%
      \ifx&#3&%
      \else%
      \nopagebreak[4]#3\nopagebreak[4]\\\nopagebreak[4]%
      \fi%
% 
      \ifx&#4&%
      \else%
      \nopagebreak[4]\vspace{0.5em}\nopagebreak[4]
%
      \nopagebreak[4]\footnotesize\emph{#4}\nopagebreak[4]%
      \fi%
    \nopagebreak[4]\end{center}\nopagebreak[4]}

\title{Title}
\author{Author}
\date{\today}

\begin{document}
\maketitle

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed non risus. Suspendisse lectus tortor, dignissim sit amet, adipiscing nec, ultricies sed, dolor. Cras elementum ultrices diam. Maecenas ligula massa, varius a, semper congue, euismod non, mi. Proin porttitor, orci nec nonummy molestie, enim est eleifend mi, non fermentum diam nisl sit amet erat. Duis semper. Duis arcu massa, scelerisque vitae, consequat in, pretium a, enim. Pellentesque congue. Ut in risus volutpat libero pharetra tempor. Cras vestibulum bibendum augue. Praesent egestas leo in pede. Praesent blandit odio eu enim. Pellentesque sed dui ut augue blandit sodales. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Aliquam nibh. Mauris ac mauris sed pede pellentesque fermentum. Maecenas adipiscing ante non diam sodales hendrerit.

Ut velit mauris, egestas sed, gravida nec, ornare ut, mi. Aenean ut orci vel massa suscipit pulvinar. Nulla sollicitudin. Fusce varius, ligula non tempus aliquam, nunc turpis ullamcorper nibh, in tempus sapien eros vitae ligula. Pellentesque rhoncus nunc et augue. Integer id felis. Curabitur aliquet pellentesque diam. Integer quis metus vitae elit lobortis egestas. Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Morbi vel erat non mauris convallis vehicula. Nulla et sapien. Integer tortor tellus, aliquam faucibus, convallis id, congue eu, quam. Mauris ullamcorper felis vitae erat. Proin feugiat, augue non elementum posuere.


\newtitle{9 symphony}{Bethoven}{1922}{Lipsum}

Ut velit mauris, egestas sed, gravida nec, ornare ut, mi. Aenean ut orci vel massa suscipit pulvinar. Nulla sollicitudin. Fusce varius, ligula non tempus aliquam, nunc turpis ullamcorper nibh, in tempus sapien eros vitae ligula. Pellentesque rhoncus nunc et augue. Integer id felis. Curabitur aliquet pellentesque diam. Integer quis metus vitae elit lobortis egestas. Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Morbi vel erat non mauris convallis vehicula. Nulla et sapien. Integer tortor tellus, aliquam faucibus, convallis id, congue eu, quam. Mauris ullamcorper felis vitae erat. Proin feugiat, augue non elementum posuere, metus purus iaculis lectus, et tristique ligula justo vitae magna.
Aliquam convallis sollicitudin purus.

\end{document}

I get the widow title at the bottom page:

Rendering example page

So, how can I avoid this behavior and get the same behavior than \section command witch force the following text to be in the same page?

0

When you want to keep several lines or paragraphs together, no need to use \nopagebreak[4] everywhere: put it all inside a box (typically, a minipage environment or a \parbox command). This prevents page breaks within the title stuff. To prevent page breaks after the title, you can use something like this:

  \par\nopagebreak\vspace{4ex plus .1ex minus .1ex}%
  % Uncomment this if you want to suppress paragraph indentation after the title
  % \@afterindentfalse
  \@afterheading

It is critically important that \nopagebreak (or the \nobreak TeX command) comes before the \vspace. The rules for when a line break or a page break are allowed are well explained in the TeXbook (not in Lamport's LaTeX book...). If you really want to understand why this construct works, you can read it. Here is the full example with some more changes (in particular, I prefer using the ex unit rather than em in the vertical direction, because of their supposed definitions):

\documentclass{article}
\usepackage{etoolbox}
\usepackage{lipsum}

\makeatletter

% \newtitle{<Title>}{<Author>}{<Date>}{<miscellaneous indications>}
\newcommand*{\newtitle}[4]{%
  \par\vspace{2ex}

  \noindent
  \begin{minipage}{\linewidth}
    \begin{center}
      \textbf{\LARGE #1}\par\vspace{1ex}

      \Large #2\par\vspace{0.5ex}

      \ifblank{#3}{}{#3\par}%

      \ifblank{#4}{}{%
        \vspace{0.5ex}% this percent sign could be removed (vertical mode)
        \footnotesize\emph{#4}%
      }%
    \end{center}
  \end{minipage}%
  \par\nopagebreak\vspace{4ex plus .1ex minus .1ex}%
  % Uncomment this if you want to suppress paragraph indentation after the title
  % \@afterindentfalse
  \@afterheading
}

\makeatother

\title{Title}
\author{Author}
\date{\today}

\begin{document}
\maketitle

\lipsum[1-2]\lipsum[3][1-14] One% more word is enough
\newtitle{9\textsuperscript{th}~symphony}{Beethoven}{1922}{Lipsum}
%
\lipsum[4]
\end{document}

Page 1

enter image description here


Page 2

enter image description here

If you uncomment only the “more” word where I have written “One more word is enough“, your whole \newtitle is postponed to the next page, as desired:

Page 1

enter image description here


Page 2

enter image description here

1

Well, your \newtitle is a little bit large, isn't it?

The issue here is that an automatic can not solve each situation. Your problem here is simply, that your newtitle fits at the end of the page (and the white space would be very large) so the newtitle is set. If you add an small text, for example text. text % <==== before your newtitle, situation changed. Now the space is not enouph for your very large newtitle ...

See the code:

\documentclass[a4paper,12pt]{article}

% \newtitle{<Title>}{<Author>}{<Date>}{<miscellaneous indications>}
\newcommand{\newtitle}[4]{%
  \vspace{2em}
  \begin{center}
    \textbf{\LARGE #1}\nopagebreak[4]\vspace{1em}\nopagebreak[4]\\\nopagebreak[4]
%
    \nopagebreak[4]\Large #2\nopagebreak[4]\vspace{0.5em}\nopagebreak[4]\\\nopagebreak
%
    \ifx&#3&%
    \else%
      \nopagebreak[4]#3\nopagebreak[4]\\\nopagebreak[4]%
    \fi%
% 
    \ifx&#4&%
    \else%
      \nopagebreak[4]\vspace{0.5em}\nopagebreak[4]
%
      \nopagebreak[4]\footnotesize\emph{#4}\nopagebreak[4]%
    \fi%
    \nopagebreak[4]%
  \end{center}%
  \nopagebreak[4]%
}

\title{Title}
\author{Author}
\date{\today}


\begin{document}
\maketitle

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed non risus. 
Suspendisse lectus tortor, dignissim sit amet, adipiscing nec, ultricies 
sed, dolor. Cras elementum ultrices diam. Maecenas ligula massa, varius 
a, semper congue, euismod non, mi. Proin porttitor, orci nec nonummy 
molestie, enim est eleifend mi, non fermentum diam nisl sit amet erat. 
Duis semper. Duis arcu massa, scelerisque vitae, consequat in, pretium 
a, enim. Pellentesque congue. Ut in risus volutpat libero pharetra 
tempor. Cras vestibulum bibendum augue. Praesent egestas leo in pede. 
Praesent blandit odio eu enim. Pellentesque sed dui ut augue blandit 
sodales. Vestibulum ante ipsum primis in faucibus orci luctus et 
ultrices posuere cubilia Curae; Aliquam nibh. Mauris ac mauris sed pede 
pellentesque fermentum. Maecenas adipiscing ante non diam sodales 
hendrerit.

Ut velit mauris, egestas sed, gravida nec, ornare ut, mi. Aenean ut orci 
vel massa suscipit pulvinar. Nulla sollicitudin. Fusce varius, ligula 
non tempus aliquam, nunc turpis ullamcorper nibh, in tempus sapien eros 
vitae ligula. Pellentesque rhoncus nunc et augue. Integer id felis. 
Curabitur aliquet pellentesque diam. Integer quis metus vitae elit 
lobortis egestas. Lorem ipsum dolor sit amet, consectetuer adipiscing 
elit. Morbi vel erat non mauris convallis vehicula. Nulla et sapien. 
Integer tortor tellus, aliquam faucibus, convallis id, congue eu, quam. 
Mauris ullamcorper felis vitae erat. Proin feugiat, augue non elementum 
posuere.

text. text % <==========================================================


\newtitle{9 symphony}{Bethoven}{1922}{Lipsum}
Ut velit mauris, egestas sed, gravida nec, ornare ut, mi. Aenean ut orci 
vel massa suscipit pulvinar. Nulla sollicitudin. Fusce varius, ligula 
non tempus aliquam, nunc turpis ullamcorper nibh, in tempus sapien eros 
vitae ligula. Pellentesque rhoncus nunc et augue. Integer id felis. 
Curabitur aliquet pellentesque diam. Integer quis metus vitae elit 
lobortis egestas. Lorem ipsum dolor sit amet, consectetuer adipiscing 
elit. Morbi vel erat non mauris convallis vehicula. Nulla et sapien. 
Integer tortor tellus, aliquam faucibus, convallis id, congue eu, quam. 
Mauris ullamcorper felis vitae erat. Proin feugiat, augue non elementum 
posuere, metus purus iaculis lectus, et tristique ligula justo vitae 
magna.
Aliquam convallis sollicitudin purus.

\end{document}

and its result:

resulting pdf

Another result you get if you add some Lipsum. into your \newtitle in your given code. The you get an pagebreak inside this fourth parameter in your command \newtitle. Please see the following code

\documentclass[a4paper,12pt]{article}

% \newtitle{<Title>}{<Author>}{<Date>}{<miscellaneous indications>}
\newcommand{\newtitle}[4]{%
  \nopagebreak[4]%
  \vspace{2em}
  \begin{center}
    \textbf{\LARGE #1}\nopagebreak[4]\vspace{1em}\nopagebreak[4]\\\nopagebreak[4]
%
    \nopagebreak[4]\Large #2\nopagebreak[4]\vspace{0.5em}\nopagebreak[4]\\\nopagebreak
%
    \ifx&#3&%
    \else%
      \nopagebreak[4]#3\nopagebreak[4]\\\nopagebreak[4]%
    \fi%
% 
    \ifx&#4&%
    \else%
      \nopagebreak[4]\vspace{0.5em}\nopagebreak[4]
%
      \nopagebreak[4]\footnotesize\emph{#4}\nopagebreak[4]%
    \fi%
    \nopagebreak[4]%
  \end{center}%
  \nopagebreak[4]%
}

\title{Title}
\author{Author}
\date{\today}


\begin{document}
\maketitle

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed non risus. 
Suspendisse lectus tortor, dignissim sit amet, adipiscing nec, ultricies 
sed, dolor. Cras elementum ultrices diam. Maecenas ligula massa, varius 
a, semper congue, euismod non, mi. Proin porttitor, orci nec nonummy 
molestie, enim est eleifend mi, non fermentum diam nisl sit amet erat. 
Duis semper. Duis arcu massa, scelerisque vitae, consequat in, pretium 
a, enim. Pellentesque congue. Ut in risus volutpat libero pharetra 
tempor. Cras vestibulum bibendum augue. Praesent egestas leo in pede. 
Praesent blandit odio eu enim. Pellentesque sed dui ut augue blandit 
sodales. Vestibulum ante ipsum primis in faucibus orci luctus et 
ultrices posuere cubilia Curae; Aliquam nibh. Mauris ac mauris sed pede 
pellentesque fermentum. Maecenas adipiscing ante non diam sodales 
hendrerit.

Ut velit mauris, egestas sed, gravida nec, ornare ut, mi. Aenean ut orci 
vel massa suscipit pulvinar. Nulla sollicitudin. Fusce varius, ligula 
non tempus aliquam, nunc turpis ullamcorper nibh, in tempus sapien eros 
vitae ligula. Pellentesque rhoncus nunc et augue. Integer id felis. 
Curabitur aliquet pellentesque diam. Integer quis metus vitae elit 
lobortis egestas. Lorem ipsum dolor sit amet, consectetuer adipiscing 
elit. Morbi vel erat non mauris convallis vehicula. Nulla et sapien. 
Integer tortor tellus, aliquam faucibus, convallis id, congue eu, quam. 
Mauris ullamcorper felis vitae erat. Proin feugiat, augue non elementum 
posuere.

%text. text % <==========================================================


\newtitle{9 symphony}{Bethoven}{1922}{Lipsum. Lipsum. Lipsum. Lipsum. 
  Lipsum. Lipsum. Lipsum. Lipsum. Lipsum. Lipsum. Lipsum. Lipsum. Lipsum. 
  Lipsum. Lipsum. Lipsum. Lipsum. Lipsum. Lipsum. Lipsum. } % <=========
Ut velit mauris, egestas sed, gravida nec, ornare ut, mi. Aenean ut orci 
vel massa suscipit pulvinar. Nulla sollicitudin. Fusce varius, ligula 
non tempus aliquam, nunc turpis ullamcorper nibh, in tempus sapien eros 
vitae ligula. Pellentesque rhoncus nunc et augue. Integer id felis. 
Curabitur aliquet pellentesque diam. Integer quis metus vitae elit 
lobortis egestas. Lorem ipsum dolor sit amet, consectetuer adipiscing 
elit. Morbi vel erat non mauris convallis vehicula. Nulla et sapien. 
Integer tortor tellus, aliquam faucibus, convallis id, congue eu, quam. 
Mauris ullamcorper felis vitae erat. Proin feugiat, augue non elementum 
posuere, metus purus iaculis lectus, et tristique ligula justo vitae 
magna.
Aliquam convallis sollicitudin purus.

\end{document}

and its result:

enter image description here

At last it is not very clear if the second case can happen for you, and perhaps package needspace can help you, but at the moment I think your case is so special, that it would be better you simple use \newpage or \clearpage to get your \newtitle to the next page:

\documentclass[a4paper,12pt]{article}

% \newtitle{<Title>}{<Author>}{<Date>}{<miscellaneous indications>}
\newcommand{\newtitle}[4]{%
  \nopagebreak[4]%
  \vspace{2em}
  \begin{center}
    \textbf{\LARGE #1}\nopagebreak[4]\vspace{1em}\nopagebreak[4]\\\nopagebreak[4]
%
    \nopagebreak[4]\Large #2\nopagebreak[4]\vspace{0.5em}\nopagebreak[4]\\\nopagebreak
%
    \ifx&#3&%
    \else%
      \nopagebreak[4]#3\nopagebreak[4]\\\nopagebreak[4]%
    \fi%
% 
    \ifx&#4&%
    \else%
      \nopagebreak[4]\vspace{0.5em}\nopagebreak[4]
%
      \nopagebreak[4]\footnotesize\emph{#4}\nopagebreak[4]%
    \fi%
    \nopagebreak[4]%
  \end{center}%
  \nopagebreak[4]%
}

\title{Title}
\author{Author}
\date{\today}


\begin{document}
\maketitle

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed non risus. 
Suspendisse lectus tortor, dignissim sit amet, adipiscing nec, ultricies 
sed, dolor. Cras elementum ultrices diam. Maecenas ligula massa, varius 
a, semper congue, euismod non, mi. Proin porttitor, orci nec nonummy 
molestie, enim est eleifend mi, non fermentum diam nisl sit amet erat. 
Duis semper. Duis arcu massa, scelerisque vitae, consequat in, pretium 
a, enim. Pellentesque congue. Ut in risus volutpat libero pharetra 
tempor. Cras vestibulum bibendum augue. Praesent egestas leo in pede. 
Praesent blandit odio eu enim. Pellentesque sed dui ut augue blandit 
sodales. Vestibulum ante ipsum primis in faucibus orci luctus et 
ultrices posuere cubilia Curae; Aliquam nibh. Mauris ac mauris sed pede 
pellentesque fermentum. Maecenas adipiscing ante non diam sodales 
hendrerit.

Ut velit mauris, egestas sed, gravida nec, ornare ut, mi. Aenean ut orci 
vel massa suscipit pulvinar. Nulla sollicitudin. Fusce varius, ligula 
non tempus aliquam, nunc turpis ullamcorper nibh, in tempus sapien eros 
vitae ligula. Pellentesque rhoncus nunc et augue. Integer id felis. 
Curabitur aliquet pellentesque diam. Integer quis metus vitae elit 
lobortis egestas. Lorem ipsum dolor sit amet, consectetuer adipiscing 
elit. Morbi vel erat non mauris convallis vehicula. Nulla et sapien. 
Integer tortor tellus, aliquam faucibus, convallis id, congue eu, quam. 
Mauris ullamcorper felis vitae erat. Proin feugiat, augue non elementum 
posuere.

\clearpage % <==========================================================
\newtitle{9 symphony}{Bethoven}{1922}{Lipsum.}
Ut velit mauris, egestas sed, gravida nec, ornare ut, mi. Aenean ut orci 
vel massa suscipit pulvinar. Nulla sollicitudin. Fusce varius, ligula 
non tempus aliquam, nunc turpis ullamcorper nibh, in tempus sapien eros 
vitae ligula. Pellentesque rhoncus nunc et augue. Integer id felis. 
Curabitur aliquet pellentesque diam. Integer quis metus vitae elit 
lobortis egestas. Lorem ipsum dolor sit amet, consectetuer adipiscing 
elit. Morbi vel erat non mauris convallis vehicula. Nulla et sapien. 
Integer tortor tellus, aliquam faucibus, convallis id, congue eu, quam. 
Mauris ullamcorper felis vitae erat. Proin feugiat, augue non elementum 
posuere, metus purus iaculis lectus, et tristique ligula justo vitae 
magna.
Aliquam convallis sollicitudin purus.

\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.