3

ConTeXt: How do I get multi-level descriptions? The contextgarden example does not work shows how to get nested descriptions, but each description begins on the same line as the label that it describes. How do I get the description to begin on a new line, so that the label is on a line of its own?

The ConTeXt code described in the abovementioned answer is

\setuppapersize[A5]
\definedescription
  [descr]
  [
    headstyle=bold, 
    style=normal,
    align=flushleft,
    alternative=hanging, 
    width=broad,
    margin=1cm,
  ]

\starttext
\startdescr{Para}
  This is a shorter item label, and some text that talks about it.
  The text is wrapped into a paragraph, with successive lines indented.

  This is another paragraph under the "Para" item.
  \startdescr{Sub Item}  
    This is a description of an item which is within the "Para" item.
  \stopdescr
  \startdescr{Sub Item} 
    Another Sub Item 
  \stopdescr
\stopdescr
\startdescr{Short}
  A short item that's not part of that really long "Para" item.
\stopdescr

\stoptext

and yields text formatted schematically like this:

Para   This is a shorter item label, and some text that
    talks about it.  The text is wrapped into a paragraph,
    with successive lines indented.
    This is another paragraph under the "Para" item.

    Sub Item   This is a description of an item which
         is within the "Para" item.

    Sub Item   Another Sub Item.

Short    A short item that's not part of that really long
    "Para" item.

What I'm looking for is as follows:

Para   
    This is a shorter item label, and some text that talks
    about it.  The text is wrapped into a paragraph, with
    successive lines indented.
    This is another paragraph under the "Para" item.

    Sub Item
        This is a description of an item which is within
        the "Para" item.

    Sub Item
        Another Sub Item.

Short
    A short item that's not part of that really long
    "Para" item.

I've tried all kinds of things, using the 'command', 'before', 'inbetween', 'after', 'headcommand' options of \definedescription (see http://wiki.contextgarden.net/Command/setupdescriptions), with \crlf, \par, \vspace, but nothing I tried gave the desired effect.

1 Answer 1

4

To place the title of your description before the content you have to use alternative=top in the setup. As the title is indented by the same amount as the content when you use the margin key you have to move it to the left with the \offset which is applied with the headcommand key.

\define[1]\DescriptionHeadCommand
  {\offset[leftoffset=-1cm]{#1}}

\definedescription
  [descr]
  [alternative=top,
   margin=1cm,
   headcommand=\DescriptionHeadCommand]

\showframe[text][text]

\starttext

\startdescr{Knuth}
\input knuth
\stopdescr

\stoptext

Description with title on the top.

3
  • This specific example works for me, but if I use the same technique in my giant document then all labels show up as literal text #1 -- except if I place the \DescriptionHeadCommand definition at the very beginning of the document. Oct 12, 2015 at 8:55
  • Maybe you’re using \asciimode in your document which would explain this. Oct 12, 2015 at 16:06
  • That was an excellent deduction: the document does call \asciimode, and the solution works if I place it before that call. Oct 14, 2015 at 9:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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