[Tex/LaTex] Format table of contents with LaTex

formattingtable of contents

Is it possible with LaTeX commands, or a LaTeX package, to format the Table Of Contents (TOC) of a book so that the TOC looks like this :


Table des matières

Chapter I - MyChapter1

I.1 MySection1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .  1

I.1.1 MySubSection1 (1).

I.2 MySection2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .  3

I.2.1 MySubSection1 (3). I.2.2 MySubSection2 (9)I.2.3 MySubSection3 (11). 
I.2.4 MySubSection4 (12).


Chapter II - MyChapter2

II.1 MySection1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11

II.1.1 MySubSection1 (12)

II.2 MySection2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12

II.2.1 MySubSection1 (12). II.2.2 MySubSection2 (13).II.2.3 MySub
Section3 (15). II.2.4 MySubSection4 (16). II.2.5 MySubSection5 
(17). II.2.6 MySubSection6 (18).II.2.7 MySubSection7 (21). II.2.8 
MySubSection8 (27).II.2.9 MySubSection9 (40). II.2.10 MySubSection
10 (45).II.2.11 MySubSection11 (46). II.2.12 MySubSection12 (53). 
II.2.13 MySubSection13 (54). II.2.14 MySubSection14 (58).

So that :

  • Each chapter title is displayed with the prefix "Chapter " and no reference to the page of the book.

  • Each Section is shown with the reference on the right of the toc to the book page and separated with some "…."

  • The list of subsection is displayed as ()…

(note: numbering issues are already solved)

Best Answer

You can achieve your desired format using the titletoc format.

screenshot

I have used the command titlecontents command

\titlecontents{<section>}
[]             % left margin
{}             % above code
{}             % numbered format
{}             % unnumbered format
{}             % filler-page-format, e.g dots

to customize the chapter, and its sibling command titlecontents* (which removes line breaks between entries) to customize the subsection format.

This is compatible with the hyperref package, should you wish to load it.

Here's a complete MWE for you to play with.

% arara: pdflatex
% arara: pdflatex
\documentclass{book}
\usepackage{lipsum}
\usepackage{titlesec}
\usepackage{titletoc}

% indented subsection (in toc)
\titlecontents{chapter}
[0.0cm]             % left margin
{\vspace{1cm}}                  % above code
{%                  % numbered format
{{\scshape Chapter} \thecontentslabel---}%
}%
{}         % unnumbered format
{}         % filler-page-format, e.g dots

% indented subsection (in toc)
\titlecontents*{subsection}
[1.0cm]             % left margin
{}                  % above code
{%                  % numbered format
{\thecontentslabel. }%
}%
{}         % unnumbered format
{ (\thecontentspage)}         % filler-page-format
[.~]


\begin{document}
\tableofcontents

\chapter{mychapter} 
\section{mysection}
\subsection{mysubsection}
\section{mysection}
\subsection{mysubsection}
\subsection{mysubsection}
\subsection{mysubsection}
\subsection{mysubsection}
\subsection{mysubsection}
\chapter{mychapter} 
\section{mysection}
\subsection{mysubsection}
\section{mysection}
\subsection{mysubsection}
\subsection{mysubsection}
\subsection{mysubsection}
\subsection{mysubsection}
\subsection{mysubsection}
\chapter{mychapter} 
\end{document}