# How to center the TOC?

I would like to design the table of contents aligned to a vertical line near the center of the page. The chapter and section titles need to be flushright, the numbers flushleft, and between titles and numbers, I'd like to place a separating element. It can be done easily by a tabular:

\begin{tabular}{>{\raggedleft}m{0.4\textwidth}>{\centering}m{0.3cm}>{\raggedright}m{0.4\textwidth}}
First section title & \textbullet & 27 \tabularnewline
\end{tabular}


You can see the result of the code above on this image:

But how can I build a tabular with the LaTeX \tableofcontents command? What commands do I need to redefine? After some googling I haven't found any ready solution.

-

For the chapter insert any symbol you like, instead of the \Large\textbullet

\documentclass{book}
\usepackage{xcolor,ragged2e}
\usepackage{array}
\makeatletter
\def\MBox#1#2#3#4{%
\parbox[t]{0.4\linewidth}{\RaggedLeft#1}%
\makebox[0.1\linewidth]{\color{red}#2}%
\makebox[0.4\linewidth][l]{#3}\\[#4]}
\renewcommand*\l@chapter   [2]{\par\MBox{\bfseries\Large#1}{\Large\textbullet}{#2}{5pt}}
\renewcommand*\l@section   [2]{    \MBox{\bfseries\large#1}{\textbullet}{#2}{2pt}}
\renewcommand*\l@subsection[2]{    \MBox{\bfseries      #1}{\textbullet}{#2}{1pt}}
\renewcommand\numberline[1]{}
\makeatother

\begin{document}

\tableofcontents
\chapter{First Chapter}
\section{foo}
\newpage
\section{bar}
\newpage
\subsection{foobar}
foobar
\section{An extraordinary long section title which should have a linebreak
bar

\end{document}


-
wonderful, thanks! i have never thought that it's so simple. –  deeenes Mar 2 '11 at 22:04

Have a look into the source of your document class, where all mentioned macros are defined. The source is on your local drive, use your search feature or kpsewhich to locate it, such as

kpsewhich book.cls


at the command prompt. On Linux, I often directly use it like

gedit kpsewhich book.cls


Actually, I made a shell function for that, to ease the frequent access of source code.

-
thank you! maybe i'll try also this way, because the vertical centering of the numbers in the case of section titles wrapped to more line. –  deeenes Mar 2 '11 at 22:06