# Prevent page break after end of environment (e.g. verse)

I have been typesetting verse and prose recently, and I am having trouble with dates. Specifically, I want to have the date follow the preceding text immediately, and stick to it (e.g., no pagebreak). This seems to be obvious whenever prose is being typeset---see this workaround:

\newcommand{\dated}[1]{\nobreak\par\noindent\null\hfill\textit{#1}}


However, with verse in verse environment, it becomes virtually impossible since LaTeX thinks that a break is always favourable after the \end{verse}, the end of the environment. I have been googling, but could not find the way to prevent it from breaking after the environment.

With prose, it works like a charm:

\documentclass[12pt, oneside]{article}
\usepackage[utf8]{inputenc}
\usepackage[papersize={11cm, 15cm}, textwidth=10cm, textheight=11.2cm]{geometry}
\usepackage{lipsum}
\newcommand{\dated}[1]{\nobreak\par\noindent\null\hfill\textit{#1}}

\begin{document}
\null\vspace{2.3cm}
\lipsum[1]
\dated{30.01.2018}
\end{document}


However, with poetry, not so much:

\documentclass[12pt, oneside]{article}
\usepackage[utf8]{inputenc}
\usepackage[papersize={11cm, 15cm}, textwidth=10cm, textheight=11.2cm]{geometry}
\usepackage{lipsum}
\newcommand{\dated}[1]{\nobreak\par\noindent\null\hfill\textit{#1}}

\begin{document}
\lipsum[1]

\begin{verse}
THERE was a young lady of Niger \\
Who smiled as she rode on a Tiger; \\
They came back from the ride    \\
And the smile on the face of the Tiger.
\end{verse}
\dated{30.01.2018}
\end{document}


I cannot use \needspace because all verse goes in between those \begin{verse} ... \end{verse}, and there are several hundred poems, so I cannot paste \needspace for each last line of verse.

Maybe it is possible to redefine verse somehow? Or any other trick to make \nobreak work after \end{verse}?

Any help is appreciated!

• Actually, I doubt \nobreak has any effect on \par. IIRC, \nobreak increases the penalties for line breaking. \nopagebreak increases the penalties for breaking a paragraph between pages, but must be applied at the beginning of the paragraph. There ARE no penalties for breaking pages between paragraphs. – John Kormylo Feb 12 '18 at 15:37

This solution puts the date INSIDE the verse environment and attaches it to the last line. While one can use \unskip or \vskip-\lastskip to remove some of the space at the end of the verse environment, if you are already on the next page it won't do you any good.

\documentclass[12pt, oneside]{article}
\usepackage[utf8]{inputenc}
\usepackage[papersize={11cm, 15cm}, textwidth=10cm, textheight=11.2cm, showframe]{geometry}
\usepackage{lipsum}
\newcommand{\dateverse}[1]{\hfill\rlap{\hspace{\rightmargin}%
\llap{\raisebox{-\baselineskip}{\textit{#1}}}}}
\begin{document}
\lipsum[1]

\begin{verse}
THERE was a young lady of Niger \\
Who smiled as she rode on a Tiger; \\
They came back from the ride    \\
And the smile on the face of the Tiger.
\dateverse{30.01.2018}
\end{verse}
\end{document}


It occurred to me that \raisebox was turning the date into a descender, and LaTeX only aligns baselines at the bottom of the page, not descenders. To move the baseline, one must include the previous line inside a box.

\documentclass[12pt, oneside]{article}
\usepackage[utf8]{inputenc}
\usepackage[papersize={11cm, 15cm}, textwidth=10cm, textheight=11.2cm, showframe]{geometry}
\usepackage{lipsum}
\newcommand{\dated}[1]{\ifvmode\else\newline\fi
\null\hfill\rlap{\hspace{\rightmargin}\llap{\textit{#1}}}}
\begin{document}
\lipsum[1]

\begin{verse}
THERE was a young lady of Niger \\
Who smiled as she rode on a Tiger; \\
They came back from the ride    \\