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

share|improve this question
add comment

2 Answers

up vote 7 down vote accepted

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
         in the table of contents}
bar

\end{document}

enter image description here

share|improve this answer
    
wonderful, thanks! i have never thought that it's so simple. –  vizipok Mar 2 '11 at 22:04
add comment
  • Redefine \tableofcontents to produce the tabular environment

  • Redefine \l@chapter, \l@section etc. to produce the rows of the table. These macros take two arguments. Use makeatletter and \makeatother.

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.

share|improve this answer
    
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. –  vizipok Mar 2 '11 at 22:06
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.