# Prevent page break after first line of example

I would like to find a way to prevent a page break between the first line of the example in following code.

\documentclass{article}
\usepackage{lipsum}
\usepackage{gb4e}

\begin{document}

\lipsum[3-7]

Some extra text to get the page break in the right place.

\begin{exe}
\ex\label{Label} Some description of this example
\begin{xlist}
\ex[*] {
First sentence.}
\ex[] {
First sentence.}
\ex[*] {
Third sentence.}
\end{xlist}
\end{exe}
\end{document}


I don't have a problem with a page break after the first actual item (i.e. between items (a) and (b)). I just don't want the title/heading of the example to be separated from the actual items of the example.

It's important that the example be formatted with the gb4e package (rather than a more generic list environment), as I have many examples with complex linguistic glosses that require a package dedicated to the issue. I would prefer to use this package, as I have a lot of examples already formatted for this package (as opposed to other packages for linguistic examples).

I know that there are many questions on this site dealing with preventing or forcing page breaks at specific points, but I have not found an answer that works with the examples made using the gb4e package. I have attempted adding things like \nopagebreak in the example itself or \goodbreak before the example, but the page break remains in the same place.

Finally, I was able to force the whole example to the next page by putting it in a minipage environment, but this has two disadvantages. First, it does not allow a break between (a) and (b) in the example when that would be fine. Second, it would require manually checking for these orphans. That is not very practical for long documents (e.g. a dissertation).

Try and use the following \nolistbreak just before your (nested) xlist:

\makeatletter
\newcommand{\nolistbreak}{%
\let\oldpar\par\def\par{\oldpar\nobreak}% Any \par issues a \nobreak
\@nobreaktrue% Don't break with first \item
}
\makeatletter


Two things are happening here:

1. Both exe and xlist create a list environment, and these lists performs a bunch of tests at its inception. One of which is to issue a new paragraph (via \par). We update \par to always issue a \nobreak after it (you can adjust this);
2. The first item also issues a reacts differently when \@nobreaktrue, setting some arbitrarily high penalty.

I'm not sure whether this may break something else, so use with caution. The changes initiated via a \nolistbreak call will be local in scope to the environment its call within, so it may not be too bad.

\documentclass{article}
\usepackage{lipsum,gb4e}

\makeatletter
\newcommand{\nolistbreak}{%
\let\oldpar\par\def\par{\oldpar\nobreak}% Any \par issues a \nobreak
\@nobreaktrue% Don't break with first \item
}
\makeatletter
\begin{document}

\lipsum[3-7]

Some extra text to get the page break in the right place.
\begin{exe}
\ex\label{Label} Some description of this example
\nolistbreak
\begin{xlist}
\ex[*] {
First sentence.}
\ex[] {
First sentence.}
\ex[*] {
Third sentence.}
\end{xlist}
\end{exe}
\end{document}