9

I'm using enumitem to create a description list.

These lists can sometimes be nested and can get very long. When a list item with a lot of description text breaks over a page it is difficult to tell to which item the current description belongs.

In these cases, I would like to put a note at the top of the page that shows the preceding item name, "continued".

Here is a MWE. I have put in the textsuperscript text manually; what I would like to do is make that happen automatically any time the list goes over a pagebreak.

\documentclass{book}
\usepackage{enumitem}

\newlist{Options}{description}{5}
\setlist[Options]{topsep=0.25em plus 0.2em minus 0.1em,
        parsep=0.5\baselineskip plus .1\baselineskip minus .1\baselineskip,
        itemsep=0.25em plus 0.2em minus 0.1em,
        partopsep=0pt,
}
\newcommand*{\Option}[1]{%
    \item[#1]\mbox{}\newline%
}

\begin{document}

\begin{Options}
    \Option{first item} and explanatory text
    \Option{second item} and more text%
        \clearpage\textsuperscript{second item \emph{continued}}\newline%
        more text describing the second item.
    \end{Options}

\end{document}

Here is another case using nested options:

\begin{Options}
    \Option{first item} and explanatory text
    \Option{second item} and more text%
        \begin{Options}
            \Option{nested option} text
        \end{Options}

    text that belongs to \emph{second item}\clearpage
    more text about \emph{second item}

\end{Options}
2
  • 2
    Should the note be part of the text? If so, should it be formatted like an \item from the list? Or, should the note be presented in the header or footer of the document?
    – A.Ellett
    Jul 24, 2014 at 15:55
  • Thats a good question. I think it would be more natural looking if the note starts the text block, possibly in a different font or gray color.
    – Tim A
    Jul 24, 2014 at 16:29

1 Answer 1

4

You can do this using the atbegshi package, together with an \if... statement where you set the \if... equal to true at the start of the option and then to false at the end using \setlist.

Here's a MWE. I have used the same continuation message that you used above.

\documentclass{book}
\usepackage{enumitem}
\usepackage{atbegshi}

\newif\ifInOptions\InOptionsfalse
\newlist{Options}{description}{5}
\setlist[Options]{topsep=0.25em plus 0.2em minus 0.1em,
        parsep=0.5\baselineskip plus .1\baselineskip minus .1\baselineskip,
        itemsep=0.25em plus 0.2em minus 0.1em,
        partopsep=0pt,before=\InOptionstrue,after=\InOptionsfalse,
}
\let\lastOption\relax
\newcommand*{\Option}[1]{\def\lastOption{#1}% remember the option for continued...
    \item[#1]\mbox{}\newline%
}
\AtBeginShipout{\ifInOptions%
  \AtBeginShipoutNext{\textsuperscript{\lastOption \emph{continued}}\newline}%
\fi}

\begin{document}
  \begin{Options}
    \Option{first item} and explanatory text
    \Option{second item} and more text%
        \clearpage%\textsuperscript{second item \emph{continued}}\newline%
        more text describing the second item.
  \end{Options}
\end{document}

This even seems to play well with nested environments because the \ifInOptions is implicitly set within \begin{group}...\end{group}.

5
  • However, with nested options, when the parent option continues after the nested list and a page-break occurs, the text still refers to the nested option. I'll edit the original question with an example.
    – Tim A
    Jul 25, 2014 at 14:11
  • @TimA Funny, there seemed to be a very complimentary comment here yesterday:) I don't have time to play with this now but I suspect that my \gdef is over zealous and that changing this is to a \def will fix the problem. Have just edited the solution so it is clear what I mean and will check to see if it works latter.
    – user30471
    Jul 25, 2014 at 22:19
  • @TimA I just checked and, as I suspected, using \def instead of \gdef it does remember the correct \Option to continue when the options are nested.
    – user30471
    Jul 26, 2014 at 4:16
  • Thanks @Andrew, that does seem to do the job now! really great example with no more code than needed: simplicity. ;-)
    – Tim A
    Jul 26, 2014 at 20:19
  • 1
    @TimA Yes, the problem with my first attempt was too much code: \gdef should have been \def, so less is clearly better!
    – user30471
    Jul 27, 2014 at 4:17

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .