0

Inside the table of contents of a latex book, I wish to add a few centered horizontal lines, just for typographic clarity (grouping chapters together). If I very naively write something like:

\addcontentsline{toc}{section}{-----------------------------------}

I do get the line in the table of contents, but also an unnecessary page number associated with it; moreover, the line is not centered. How can I insert a centered line into the table of contents without inserting an associated page number?

(I use MiKTeX and WinEdt, but I suppose that this is irrelevant)

Stefan Pinnow
  • 29,535
Franck
  • 65

1 Answers1

1

Although the principal question can be answered with \addtocontents{toc}{...}, it's instructive to use the \leaders macro to show the repetition of similar characters in the ToC:

The \mytocline command expects an argument that should be repeated.

\documentclass[oneside]{article}


\usepackage{pgffor}

\usepackage{tocloft}


\makeatletter
\DeclareRobustCommand{\mytocline}[1]{%
  \hfill\leaders\hbox{$\m@th
    \mkern \@dotsep mu\hbox{#1}\mkern \@dotsep
    mu$}\hfill
}
\makeatother



\begin{document}
\tableofcontents

\clearpage
\pagestyle{plain}
\foreach \x in {1,...,10} {%
  \section{Foo \x}
  \addtocontents{toc}{\protect\contentsline{section}{\mytocline{$\Sigma\int$}}{}}
}

\end{document}

enter image description here