[texhax] How to prevent page break in description environment item

David Carlisle d.p.carlisle at gmail.com
Sun Nov 1 01:47:13 CET 2015


On 31 October 2015 at 13:26, Moritz Sichert <moritz.sichert at googlemail.com>
wrote:

> Hi,
>
> I have this code:
>
> \begin{description}
>   \item[first item] \hfill \\
>     Description of first item
>   \item[second item] \hfill \\
>     Description of second item
> \end{description}
>
>
> And it generates something like this:
>
> First Item
>   Description of first Item
> Second Item
> -------- PAGE BREAK ----------
>   Description of second item
>
>
> How can I prevent the page break between the title of an item and its
> description?
>
> I tried adding \nopagebreak after \descriptionlabel like this:
>
> \let\orig at descriptionlabel\descriptionlabel
> \renewcommand*{\descriptionlabel}[1]{\orig at descriptionlabel
> {#1}\nopagebreak}
>
> But that didn't change anything. Adding \nopagebreak around the second
> item in the code also didn't prevent the break.
>
>
You don't really want \hfill\\ in the document markup, the document just
wants

  \item[first item]
    Description of first item

with the fact that there is a linebreak after the item label part of the
list design,
Something like the following which puts the labels into a 2-line box with
empty second line


\documentclass{article}


\renewcommand*\descriptionlabel[1]{\hspace\labelsep
 \makebox[0pt][l]{\parbox[b]{\linewidth}{%
    \normalfont\bfseries #1\\\mbox{}}\hspace{-\labelsep}}}


\begin{document}

\vspace*{41\baselineskip}

\begin{description}
  \item[first item]
    Description of first item
  \item[second item]
    Description of second item
\end{description}

\end{document}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://tug.org/pipermail/texhax/attachments/20151101/839cde6c/attachment.html>


More information about the texhax mailing list