2

Possible Duplicate:
Table of Contents with additional description of entries

I'd like to add some notes for every chapter in the table of contents. Have a look at the following minimal compiling example for the idea.

\documentclass{article}
\usepackage{blindtext}

\newcommand{\summary}[1]{\addtocontents{toc}{\textit{#1}}}
\begin{document}
\tableofcontents

\section{First Section}
\summary{This is the introduction. It will make the reader want to continue reading.}

\subsection{Subsection 2.1}
\summary{Here we will explain in detail why this is scientificly important.}


\subsubsection{SubSubsection}
\summary{There are several elements of the argument. This is the first.}

\end{document}

This works great except that I would like to have the notes indented as much as the toc entry they belong to.

How to do that?

marked as duplicate by Marco Daniel, Mico, egreg, Joseph Wright Nov 9 '11 at 14:14

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

0

You may add toc entries of the level of the last toc entry with the comments. But if the last entry was a section you have to remove the vertical space before the comment. So maybe:

\documentclass{article}

\usepackage{etoolbox}
\newcommand*{\lastlevel}{section}
\pretocmd{\section}{\def\lastlevel{section}}{}{}
\pretocmd{\subsection}{\def\lastlevel{subsection}}{}{}
\pretocmd{\subsubsection}{\def\lastlevel{subsubsection}}{}{}

\makeatletter
\newcommand{\l@summary}[2]{%
  \begingroup
    \let\@dotsep\@M
    \csname l@#2\endcsname{#1}{}%
  \endgroup
}

\newcommand{\summary}[1]{%
  \ifdefstring{\lastlevel}{section}{%
    \addtocontents{toc}{\protect\vspace{-1.0em plus -1pt}}%
  }{}%
  \addtocontents{toc}{%
    \protect\contentsline{summary}{\protect\numberline{}\normalfont\itshape
  #1}{\lastlevel}}%
}
\makeatother

\begin{document}
\tableofcontents

\section{First Section}
\summary{This is the introduction. It will make the reader want to continue reading.}

\subsection{Subsection 2.1}
\summary{Here we will explain in detail why this is scientificly important.}


\subsubsection{SubSubsection}
\summary{There are several elements of the argument. This is the first.}

\end{document}

If you want not to indent until the text but only until the number, just remove \protect\numberline{}.

\pretocmd and \ifdefstring are commands of package etoolbox. For more information about see the package manual. If you use another class, you may have to change the -1.0em plus -1pt.

enter image description here

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