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 would like to achieve table of contents with additional description for chapters/sections (see screenshot). What way would you go to achieve this? I'm wondering if it is possible to wrap the \chapter, \section etc. commands with custom taking 2 parameters. But how to generate the ToC then?

screeshot

share|improve this question
add comment

1 Answer

up vote 27 down vote accepted

You can use \addcontentsline{toc}{<sec_unit>}{<text>} or directly \addtocontents{toc}{<text>} to enter text to the .toc file. The only issue is to indent to text correctly.

Below some code which uses the book class and its internal macros. Its adds ''info'' lines which use basically the same formatting macros as the sectioning lines (for identical indention), but avoid the '.... (page number)' part. If you really want to give \chapter etc. two arguments you can do something like

\let\Chapter\chapter \def\chapter#1#2{\Chapter{#1}\chapterinfo{#2}}

Here the code:

\documentclass{book}

\makeatletter
% Basically the same as for `\l@section` etc, just `\@nodottedtocline` instead of `\@dottedtcline`:
\newcommand*\l@chapterinfo{\@nodottedtocline{0}{0.0em}{1.5em}}
\newcommand*\l@sectioninfo{\@nodottedtocline{1}{1.5em}{2.3em}}
\newcommand*\l@subsectioninfo{\@nodottedtocline{2}{3.8em}{3.2em}}
\newcommand*\l@subsubsectioninfo{\@nodottedtocline{3}{7.0em}{4.1em}}
\newcommand*\l@paragraphinfo{\@nodottedtocline{4}{10em}{5em}}
\newcommand*\l@subparagraphinfo{\@nodottedtocline{5}{12em}{6em}}

% Copied from the book class macro `\@dottedtocline`. Removed the dots and page number
\def\@nodottedtocline#1#2#3#4#5{%
  \ifnum #1>\c@tocdepth \else
    \vskip \z@ \@plus.2\p@
    {\leftskip #2\relax \rightskip \@tocrmarg \parfillskip -\rightskip
     \parindent #2\relax\@afterindenttrue
     \interlinepenalty\@M
     \leavevmode
     \@tempdima #3\relax
     \advance\leftskip \@tempdima \null\nobreak\hskip -\leftskip
     {#4}\nobreak
     \leaders\hbox{$\m@th
        \mkern \@dotsep mu\hbox{\,}\mkern \@dotsep
        mu$}\hfill
     \nobreak
     \hb@xt@\@pnumwidth{\hfil\normalfont \normalcolor }%
     \par}%
  \fi}

\makeatother

\def\chapterinfo#1{%
    \addcontentsline{toc}{chapterinfo}{%
    \noexpand\numberline{}#1}%
}
\def\sectioninfo#1{%
    \addcontentsline{toc}{sectioninfo}{%
    \noexpand\numberline{}#1}%
}
\def\subsectioninfo#1{%
    \addcontentsline{toc}{subsectioninfo}{%
    \noexpand\numberline{}#1}%
}
% same for subsubsection, etc. ...

\begin{document}
\tableofcontents

\chapter{AAA}
\chapterinfo{A very long text, a very long text, a very long text, a very long text, a very long text, a very long text, a very long text, a very long text}

\section{aaa}
\sectioninfo{A very long text, a very long text, a very long text, a very long text, a very long text, a very long text, a very long text, a very long text}

\subsection{1111}
\subsectioninfo{A very long text, a very long text, a very long text, a very long text, a very long text, a very long text, a very long text, a very long text}

\end{document}

Result:

Resulting TOC

If this is required by more people I would be ready to make a small package out of it. I could try to also support the koma script or other classes.

share|improve this answer
    
thank you, Martin –  Jakub Feb 4 '11 at 7:04
    
Sharrer : Thank you as well. For long books or proceedings, I find this kind of commented toc very user-friendly. –  ogerard May 2 '11 at 8:21
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.