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

Moritz Sichert moritz.sichert at googlemail.com
Sun Nov 1 13:07:06 CET 2015


Thanks for your help!

I ended up defining my own environment like this:

\makeatletter
\let\orig at item\@item
\newcommand{\@labelparsitem}[2]{
    \parbox{\linewidth}{
       \orig at item[#1] \hspace{\linewidth} \\
       #2 \vspace{\parsep}
    }
}

\newenvironment{labelpars}{
    \let\item\@labelparsitem
    \list{}{
        \labelwidth\z@ \itemindent-\leftmargin
        \let\makelabel\descriptionlabel
    }
}{\endlist\vspace{\partopsep}}
\makeatother


that I can use like this:

\begin{labelpars}
    \item{First Item}{Description of first item}
    \item{Second Item}{Description of Second item}
\end{labelpars}

Am 01.11.2015 um 01:47 schrieb David Carlisle:
> 
> 
> On 31 October 2015 at 13:26, Moritz Sichert
> <moritz.sichert at googlemail.com <mailto: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 --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: OpenPGP digital signature
URL: <http://tug.org/pipermail/texhax/attachments/20151101/9cfb5e15/attachment.bin>


More information about the texhax mailing list