Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I have headings that appear before items in an enumerated list. The problem is that I think it looks ugly when a heading appears at the end of a page with the content of that heading on the next page. I'd like it so that at least one line of text from the item contents appears after a heading. I've tried \nopagebreak[4] (doesn't appear to do anything?) and begin{samepage} wrapping the heading and entire paragraph (left big empty spaces on pages). I'm hoping there's a nice way to solve it!

Here's sample code to reproduce the issue:

\documentclass[letterpaper]{article}
\usepackage{enumitem}
\usepackage{lipsum}
\begin{document}
\begin{enumerate}
\item[]{\Huge{Heading}}
\item{\lipsum[1]}
\item[]{\Huge{Heading}}
\item{\lipsum[1]}
\item[]{\Huge{Heading}}
\item{\lipsum[1]}
\item[]{\Huge{Heading}}
\item{\lipsum[1]}
\end{enumerate}
\end{document}

And an image of the problematic output (see bottom of page). In this case, I'd either like the heading to be pushed to the next page or at least the first line of text from the paragraph to be pulled onto the first page.

enter image description here

share|improve this question

2 Answers 2

up vote 3 down vote accepted

The needspace package allows reserving vertical space before doing the next thing. If the space does not exist, it issues a page break. Here, I redefined \item to perform a \needspace before it. You can change the value I used (\baselineskip), but it works for your MWE.

\documentclass[letterpaper]{article}
\usepackage{enumitem}
\usepackage{lipsum}
\usepackage{needspace}
\let\svitem\item
\def\item{\needspace{\baselineskip}\svitem}
\begin{document}
\begin{enumerate}
\item[]{\Huge{Heading}}
\item{\lipsum[1]}
\item[]{\Huge{Heading}}
\item{\lipsum[1]}
\item[]{\Huge{Heading}}
\item{\lipsum[1]}
\item[]{\Huge{Heading}}
\item{\lipsum[1]}
\end{enumerate}
\end{document}

It is possible that you might still get burned, since the lipsum paragraphs will also issue a \needspace and could break a page on that account. A better way would be as follows, where a separate \Hitem is defined which alone issues the \needspace:

\documentclass[letterpaper]{article}
\usepackage{enumitem}
\usepackage{lipsum}
\usepackage{needspace}
\def\Hitem#1{\needspace{\baselineskip}\item[]{\Huge{#1}}}
\begin{document}
\begin{enumerate}
\Hitem{Heading}
\item{\lipsum[1]}
\Hitem{Heading}
\item{\lipsum[1]}
\Hitem{Heading}
\item{\lipsum[1]}
\Hitem{Heading}
\item{\lipsum[1]}
\end{enumerate}
\end{document}
share|improve this answer
    
This seems to have done the trick for me, thanks very much! –  aardvarkk Feb 21 at 20:07

A solution using the stackengine package: it's by construction that the "Heading" part cannot be separated from the first line of the content since it belongs to the first line. It also has the advantage to greatly simplify the code – unless you have specific reasons to type the heading with its own \item command:

\documentclass[a4paper]{article}
\usepackage{enumitem}
\usepackage{stackengine}
\usepackage{lipsum}
\usepackage[bottom=45mm]{geometry}
\clubpenalty = 3500
\setstackgap{S}{\baselineskip}

\begin{document}

\lipsum[1]

\begin{enumerate}[label =\arabic*.\stackon{}{\rlap{\hspace{\labelsep}\Huge Heading}}]%
\item \lipsum[1]
\item \lipsum[1]
\item \lipsum[1]
\item \lipsum[1]
\item \lipsum[1]

\end{enumerate}

\end{document}% 

enter image description here

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.