[Tex/LaTex] Custom table of contents style in ConTeXt

contexttable of contents

I want to change the style of the table of contents:

  1. Chapter entries shouldn't have a dotted line. (see below)
  2. Chapters without a number should have no left spacing. (see below)
  3. The dotted line should end at the same "x-position", no matter if the page number has one or two digits.

This is my current minimal (not entirely) working example code:

\setupcombinedlist[content][
    alternative=c,
    aligntitle=no  % has no effect?
]

\setuplist[chapter][
    alternative=b,  % has no effect?
    width=1.4em,
    style={\ss\bf},
    aligntitle=no,  % has no effect?
    before={\blank[4*big]}
]

\setuplist[section][width=2.2em]

\setupinterlinespace[line=3.4ex]  % more line spacing
\setupwhitespace[medium]  % space between paragraphs

% maybe there is a better way decrease line spacing for TOC?…
\startsectionblockenvironment[frontpart]
    \setupinterlinespace[line=1.5ex]
\stopsectionblockenvironment

\starttext
    \startfrontmatter
        \completecontent
        \chapter{Bla}
    \stopfrontmatter

    \page[8]  % to get two-digit numbers

    \startbodymatter
        \chapter{Foo}
        \section{Foo Foo}
        \section{Foo Foo}
        \chapter{Bar}
        \section{Bar Bar}
        \chapter{Baz}
        \section{Baz Baz}
    \stopbodymatter

    \startbackmatter
        \chapter{Bibliography}
    \stopbackmatter

    \startappendices
        \chapter{CD Contents}
    \stopappendices
\stoptext

Annotated result:
ConTeXt result


It should look a bit like this LaTeX version:

\documentclass[a4paper]{scrbook}

\usepackage[english]{babel}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}

\usepackage[tocfullflat]{tocstyle}
\usetocstyle{KOMAlike}

\begin{document}

\tableofcontents

\frontmatter
    \chapter{Bla}

\mainmatter
    \setcounter{page}{8}  % to get two-digit numbers
    \chapter{Foo}
    \section{Foo Foo}
    \section{Foo Foo}
    \chapter{Bar}
    \section{Bar Bar}
    \chapter{Baz}
    \section{Baz Baz}

\backmatter
    \chapter{Bibliography}

\appendix
    \chapter{CD Contents}

\end{document}

LaTeX result


Update 1:

The solution of problem 1 is quite simple: alternative=c must be removed from \setupcombinedlist[content], because this style is passed to all sublists. Instead \setupcombinedlist[section,subsection][alternative=c] enables a dotted line for sections and subsections only.

Update 2:

Problem 2 seems not to exist in newer ConTeXt version. The screenshot was created with version 2012.05.30 11:26. But version 2013.01.08 01:19 works as wanted.

Best Answer

Here is my solution to tackle the last of your three points. Actually it incorporates all three points at the same time. Here we go:

First we define a new list alternative. That's an abstract and very flexible way to set up the layout of lists (section heads use a similar mechanism BTW). I call it dotfix:

\unprotect
\definelistalternative
  [dotfix]
  [distance=0pt,
   width=2em,
   stretch=10em,
   filler=\hskip.5em\gleaders\hbox to .5em{\hss.\hss}\hfill\relax,
   renderingsetup=\??listrenderings:abc]
 \protect

The width setting adjusts the distance between the dots and the page number, this is what you're after. Now you can use the new created style, instead of the default one:

\setupcombinedlist
  [section]
  [alternative=dotfix]

The rest is more or less copied from your example.

\setuplist[chapter]
  [alternative=b,
   style=sansbold,
   before={\blank[4*big]}]

\setuplist
  [section]
  [width=2.2em]

\setupwhitespace
  [medium]

\startsectionblockenvironment[frontpart]
  \setupinterlinespace [line=1.5ex]
\stopsectionblockenvironment

\starttext

  \startfrontmatter
    \completecontent
    \startchapter [title=Bla]
    \stopchapter
  \stopfrontmatter

\startbodymatter
    \dorecurse{3}{
      \startchapter [title=Foo]
        \startsection [title=Bar]
        \stopsection
        \startsection [title=Another section]
        \stopsection
      \stopchapter}
    \setcounter [userpage] [1234]
  \stopbodymatter

  \startbackmatter
    \startchapter [title=Bibliography]
    \stopchapter
  \stopbackmatter

\stoptext

result

Related Question