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 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.

share|improve this question
 
Regarding point 2: On my system the chapters without numbers are left aligned and don't show the space from your screenshot. ConTeXt MkIV 2012.12.06 22:36 –  Marco Jan 8 '13 at 16:56
 
@Marco: I created the screenshot with version 2012.05.30 11:26. Using the currently latest version 2013.01.08 01:19 the example works as wanted. But unfortunately when compiling the real document I'm working on, the output PDF file contains only one page with the title "Contents" (no compile errors). When I install the latest stable version with first-setup.sh --context=current I get the error described here: mail-archive.com/ntg-context@ntg.nl/msg67261.html (LuaTeX version too new). I'll do some investigation, why my document does not compile using the newest ConTeXt version. –  hiddenbit Jan 8 '13 at 17:31
 
In version 2013.01.08 01:19 the way included project files are looked up seems to have changed, but I fixed this by changing file paths. I also cannot use the fonts of TeX Live any more, because mtxrun --script fonts --reload crashes in this version. Too much trouble, to just remove some tiny spacing. –  hiddenbit Jan 8 '13 at 19:10
 
That's a known bug. It should be fixed soon. –  Marco Jan 8 '13 at 19:21
 
OK, good to know. –  hiddenbit Jan 8 '13 at 19:23
add comment

1 Answer

up vote 4 down vote accepted

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

share|improve this answer
 
Thank you very much! Nearly perfect solution; just one more question: Is it possible to reduce the distance between the last dot and the number column? –  hiddenbit Jan 9 '13 at 9:29
 
\hbox to 1em{\hskip-1em\hfill\box\b_strc_lists_page} does what I want, but as I'm not a ConTeXt pro it might be not the best way. ;) –  hiddenbit Jan 9 '13 at 9:39
 
I updated my answer. I looked into it again and saw that there's no need to change the rendering setup. Use the width setting instead. –  Marco Jan 9 '13 at 12:29
 
Thanks again! This is much simpler. –  hiddenbit Jan 9 '13 at 15:59
add comment

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.
http://tex.stackexchange.com/questions/89758/custom-table-of-contents-style-in-context?answertab=active
tex.stackexchange.com
crawl=CC-MAIN-2014-10
74585
application/http; msgtype=response
sha1:CWR23TOPWTFEANQHU3Q4FE5BNXOP3HJT
<urn:uuid:82adcbfe-1d22-47fc-a372-4dcbad1d6dbe>
2014-03-14T14:37:41Z
198.252.206.140
sha1:W56XVRLALPORMT7ECZG7NWKUO54RRYWP
<urn:uuid:943664ec-349a-4cb1-9f98-b9ea856b88bb>
http://tex.stackexchange.com/questions/89758/custom-table-of-contents-style-in-context?answertab=active
response
<urn:uuid:69fd4b4b-0fe4-4b94-9399-a4d7257fccc1>
robots: classic
hostname: ip-10-183-142-35.ec2.internal
software: Nutch 1.6 (CC)/CC WarcExport 1.0
isPartOf: CC-MAIN-2014-10
operator: CommonCrawl Admin
description: Wide crawl of the web with URLs provided by Blekko for March 2014
publisher: CommonCrawl
format: WARC File Format 1.0
conformsTo: http://bibnum.bnf.fr/WARC/WARC_ISO_28500_version1_latestdraft.pdf