44
votes

I'm trying to create a LaTex document which has a "testday" and a verse full of "testItemToDo" and I want any page break to occur before the "testday" but never between a "testday" and the verse of "testItemToDo". How can I modify my LaTex file

\documentclass{article}
\begin{document}
\LARGE
{*}{*}to do\\
\begin{verse}
{*}today\nopagebreak
\begin{verse}
testItemToDo\\*testItemToDo\\*testItemToDo\\*testItemToDo\\*testItemToDo\\*testItemToDo\\*testItemToDo\\*testItemToDo
\end{verse}
{*}testDay\nopagebreak
\begin{verse}
testItemToDo\\*testItemToDo\\*testItemToDo\\*testItemToDo\\*testItemToDo\\*testItemToDo\\*testItemToDo\\*testItemToDo
\end{verse}
{*}testDay\nopagebreak
\begin{verse}
testItemToDo\\*testItemToDo\\*testItemToDo\\*testItemToDo\\*testItemToDo\\*testItemToDo\\*testItemToDo\\*testItemToDo
\end{verse}
{*}testDay\nopagebreak
\begin{verse}
testItemToDo\\*testItemToDo\\*testItemToDo\\*testItemToDo\\*testItemToDo\\*testItemToDo\\*testItemToDo\\*testItemToDo
\end{verse}
{*}testDay\nopagebreak
\begin{verse}
testItemToDo\\*testItemToDo\\*testItemToDo\\*testItemToDo\\*testItemToDo\\*testItemToDo\\*testItemToDo\\*testItemToDo
\end{verse}
\end{verse}
\end{document}
3
I'm voting to close this question as off-topic because it belongs on TeX.SECole Tobin
Can we migrate it to TeX.SE somehow?D W

3 Answers

61
votes

Surround your testday and verse with a \begin{samepage} and \end{samepage}, i.e.:

\begin{samepage}
{*}testDay
\begin{verse}
testItemToDo\\*testItemToDo\\*testItemToDo\\*testItemToDo\\*testItemToDo\\*testItemToDo\\*testItemToDo\\*testItemToDo
\end{verse}
\end{samepage}

This still allows the verse to break a page fine, provided you get rid of some \\*.

32
votes

\nopagebreak[number]

The \nopagebreak command prevents LaTeX from breaking the current page at the position of the command. With the optional argument, number, you can convert the \nopagebreak command from a demand to a request. The number must be a number from 0 to 4. The higher the number, the more insistent the request is.

Or you can change your verse to a minipage... though if the list is longer than a page, latex will probably puke.

4
votes

A very simple solution I've found is with \filbreak before each (see the FAQ).

enter image description here

\documentclass{article}
\begin{document}
\LARGE
{*}{*}to do\\
\begin{verse}
{*}today
\begin{verse}
testItemToDo\\*testItemToDo\\*testItemToDo\\*testItemToDo\\*testItemToDo\\*testItemToDo\\*testItemToDo\\*testItemToDo
\end{verse}
\filbreak
{*}testDay
\begin{verse}
testItemToDo\\*testItemToDo\\*testItemToDo\\*testItemToDo\\*testItemToDo\\*testItemToDo\\*testItemToDo\\*testItemToDo
\end{verse}
\filbreak
{*}testDay
\begin{verse}
testItemToDo\\*testItemToDo\\*testItemToDo\\*testItemToDo\\*testItemToDo\\*testItemToDo\\*testItemToDo\\*testItemToDo
\end{verse}
\filbreak
{*}testDay
\begin{verse}
testItemToDo\\*testItemToDo\\*testItemToDo\\*testItemToDo\\*testItemToDo\\*testItemToDo\\*testItemToDo\\*testItemToDo
\end{verse}
\filbreak
{*}testDay
\begin{verse}
testItemToDo\\*testItemToDo\\*testItemToDo\\*testItemToDo\\*testItemToDo\\*testItemToDo\\*testItemToDo\\*testItemToDo
\end{verse}
\end{verse}
\end{document}