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 a table of contents defined like this:

\setuphead[part][number=no]
\setuphead[chapter][number=no]
\setuphead[section][number=no]

\setuplist[part][alternative=a, margin=0em]
\setuplist[chapter][alternative=a, margin=0em]
\setuplist[section][alternative=d, margin=0em]

\starttext
    \startfrontmatter
        \completecontent
    \stopfrontmatter
    \startbodymatter
        \part{This is a part title}
            \chapter{This is a chapter title}
                \section{This is a section title}
                \section{This is another section title}
    \stopbodymatter
\stoptext

After compiling, it appears like this:

Contents

   This is a part title 2

    This is a chapter title 3
This is a section title   3 This is another section title   3

This has three problems:

  • The various section levels do not align horizontally.
  • The horizontal distance between the section title entries and the page number is different for alternative=a and alternative=d.
  • The vertical line spacing is inconsistent.

I would like to create a result like this:

Contents

This is a part title   2
This is a chapter title   3
This is a section title   3 This is another section title   3
  • Why are alternative=a and alternative=d appearing so differently?
  • How can I make the entries line up along the left, set the placement of the page number consistently, and adjust the line spacing so it is the same for all entries?
share|improve this question

1 Answer 1

up vote 4 down vote accepted
+150

How can I make the entries line up along the left, set the placement of the page number consistently, and adjust the line spacing so it is the same for all entries?

The left alignment can be controlled by setting the distance and width parameters of a list, the line spacing via the before and after keys of the next lower category (try blank[line]).

The spacing of page numbers in your section list, however, is fixed in the listalternative. To get around this you can define your own alternative command.

\setuphead    [part] [number=no]
\setuphead [chapter] [number=no]
\setuphead [section] [number=no]

%% Set the spacing left of the page number.
\newdimen \mypagenumdistance \mypagenumdistance .7em
\def\fillercmd{\nobreak\hskip\mypagenumdistance}
%% Install the spacing handler for use with alternative “a” in the part
%% and chapter list.
\setuplistalternative [a] [width=\zeropoint,filler=\fillercmd,]
%% Define a list alternative for the section list; we drop the structure
%% number (arg #1) as in the question.
\definelistplacement[my_list_placement][command]#1#2#3%
  {#2\fillercmd#3\hskip1.5em}
%% Part and chapter lists need their distance and width dimensions
%% nil’ed.
\setuplist    [part] [alternative=a, distance=\zeropoint, width=\zeropoint,before=,]
\setuplist [chapter] [alternative=a, distance=\zeropoint, width=\zeropoint,before=,]
%% Hook our list placement into the section list.
\setuplist [section] [alternative=my_list_placement]
%% Section list hook.
\startsetups toc:section
    \noindentation\placelist[section]
\stopsetups
%% Chapter list hook, with transition to the section list.
\startsetups toc:chapter
    \noindentation\placelist[chapter][after=\setups{toc:section}]
\stopsetups

\starttext
    \startfrontmatter
        %% \completecontent is imprecise, we’ll do it ourselves.
        \title{Contents}
        %% Part list is the top level structure, contains the chapter hook.
        \placelist [part] [criterium=text,after=\setups{toc:chapter}]
    \stopfrontmatter
    %% Testing section.
    \startbodymatter
      \dorecurse{3}{%
        \part{This is a part title}
          \dorecurse{5}{%
            \chapter{This is a chapter title}
                \dorecurse{10}{\section{some section title}}%
          }
      }
    \stopbodymatter
\stoptext

Which with a recent version of mkiv results in the following output: example table of contents

(You should really be asking these questions on the mailing list.)

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.