6

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)

Stefan Kottwitz
  • 231,401
  • Welcome to TeX.SX! You can have a look at our starter guide to familiarize yourself further with our format –  Mar 06 '14 at 11:47
  • This should be possible, but it is in my point of view tedious to read an 'unordered' list of subsection entries and omitting the chapter start pages as well. –  Mar 06 '14 at 11:49
  • Please provide information on the document class you use and if you're using any packages that are designed to help format the Table of Contents. – Mico Mar 06 '14 at 12:05
  • Have you had a look at tocstyle from the KOMAscript bundle? – Crissov Mar 06 '14 at 12:29
  • I understand some of you will think of this format uggly, but fortunatly the table of contents as this is reduced to 4 pages, i need this format, and fortunatly too it is readable and you have a lot of information in a little area, i like this format. Finally, i can't search by myself too much, i already took too much time formating the equation, numbering them correctly, section and chapters formating... so that if someone has a solution for this i will be glad to take it even not understanding it :-( – roberto35 Mar 06 '14 at 12:39
  • @roberto35: Have you considered the possibility of reducing the amount of entries in the toc already, by omitting the subsection information. –  Mar 06 '14 at 14:02
  • Welcome to TeX.SX! On this site, a question should typically revolve around an abstract issue (e.g. "How do I get a double horizontal line in a table?") rather than a concrete application (e.g. "How do I make this table?"). Questions that look like "Please do this complicated thing for me" tend to get closed because they are either "off topic", "too broad", or "unclear". Please try to make your question clear and simple by giving a minimal working example (MWE): you'll stand a greater chance of getting help. – Martin Schröder Mar 06 '14 at 16:50

2 Answers2

9

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}
cmhughes
  • 100,947
6

You can achieve this design with the etoc package.

The update adds code to handle the Chapter vz. Annex thing, in order for the correct (set up in French via Babel) heading in the TOC, depending on the case. In the book class, the toc file does not contain the information that we have an annex, except via the change in the numbering which goes Alphabetical. It is easier to add something in the toc to inform etoc of this, rather than testing in the chapter style if we have a Roman or an Alpha numbering.

etoc

\documentclass{book}
\usepackage[frenchb]{babel}
\usepackage[T1]{fontenc}
%\usepackage[utf8]{inputenc}
\usepackage{etoc}

% Something very close to the desired design is obtained using:
% \etoctoclines
% \etocsetlevel{subsection}{3}
% \etocsetlevel{subsubsection}{6}
% \etocsettocdepth {3}
% 
% But the way these etoc toc line styles are defined may look a bit
% frightening, thus we do not try to customize and define from scratch,
% starting from example from the sample code in section 30.5 of the
% manual
\renewcommand{\thechapter}{\Roman{chapter}}

\renewcommand*\etoctoclineleaders
{\hbox{\bfseries\normalsize\hbox to .75ex {\hss.\hss}}}

\newcommand*{\DotsAndPage}
{\nobreak\leaders\etoctoclineleaders\hfill\nobreak
 \makebox[\rightskip][r]{\bfseries\normalsize\etocpage}\par}

\etocsetstyle {chapter}
{\parindent 0pt\leftskip 0pt\relax \rightskip .75cm 
 \nobreak
 \etocskipfirstprefix}
{\pagebreak[3]\bigskip}
{\bfseries\large Chapter \etocnumber{} -- \etocname\par}
{}

\etocsetstyle {section}
{\parfillskip-\rightskip
 \nobreak\medskip
 \etocskipfirstprefix}
{\pagebreak[1]\smallskip\parfillskip-\rightskip}
{\bfseries\normalsize\etocnumber{} \etocname\DotsAndPage }
{\parfillskip 0pt plus 1fil\relax}

\etocsetstyle {subsection}
{\parfillskip 0pt plus 1fil\relax
 \nobreak\smallskip}
{}
{\mdseries\normalsize\etocnumber~\etocname{} (\etocpage). }
{\par\medskip}



\newcount\cnta
\begin{document}

\tableofcontents

\chapter{My Chapter 1}

\section{My Section 1}
\subsection{My sub section 1}

\section{My Section 2}

\cnta 0
\loop
  \advance\cnta 1
\subsection{My sub section \the\cnta}
  \ifnum\cnta<4
\repeat


\chapter{My Chapter 2}
\section{My Section 1}
\subsection{My sub section 1}
\section{My Section 2}

\cnta 0
\loop
  \advance\cnta 1
\subsection{My sub section \the\cnta}
  \ifnum\cnta<14
\repeat

\end{document}

Extended code to handle Annexes (the \appendix command) and unnumbered chapters (\backmatter).

\documentclass{book}
\usepackage[frenchb]{babel}
\usepackage[T1]{fontenc}
%\usepackage[utf8]{inputenc}
\usepackage{etoc}

\renewcommand{\thechapter}{\Roman{chapter}}
% We start from the sample code in section 30.5 of the etoc
% manual ("using depth tags")

\renewcommand*\etoctoclineleaders
{\hbox{\bfseries\normalsize\hbox to .75ex {\hss.\hss}}}

\newcommand*{\DotsAndPage}
{\nobreak\leaders\etoctoclineleaders\hfill\nobreak
 \makebox[\rightskip][r]{\bfseries\normalsize\etocpage}\par}

\etocsetstyle {chapter}
{\parindent 0pt\leftskip 0pt\relax \rightskip .75cm 
 \nobreak
 \etocskipfirstprefix}
{\pagebreak[3]\bigskip}
{\bfseries\large 
 \etocifnumbered{\ChapterOrAnnex{} \etocnumber{} -- }{}\etocname\par}
{}


% THIS IS TO GET CHAPTER OR ANNEX CORRECTLY IN THE TOC.

\newcommand*\ChapterOrAnnex{\chaptername}
\let\oldappendix\appendix
\renewcommand\appendix{\oldappendix
   \addtocontents{toc}{\def\protect\ChapterOrAnnex{\protect\appendixname}}}


\etocsetstyle {section}
{\parfillskip-\rightskip
 \nobreak\medskip
 \etocskipfirstprefix}
{\pagebreak[1]\smallskip\parfillskip-\rightskip}
{\bfseries\normalsize\etocnumber{} \etocname\DotsAndPage }
{\parfillskip 0pt plus 1fil\relax}

\etocsetstyle {subsection}
{\parfillskip 0pt plus 1fil\relax
 \nobreak\smallskip}
{}
{\mdseries\normalsize\etocnumber~\etocname{} (\etocpage). }
{\par\medskip}

\newcount\cnta
\begin{document}
\tableofcontents

\chapter{My Chapter 1}

\section{My Section 1}
\subsection{My sub section 1}

\section{My Section 2}

\cnta 0
\loop
  \advance\cnta 1
\subsection{My sub section \the\cnta}
  \ifnum\cnta<4
\repeat

\chapter{My Chapter 2}
\section{My Section 1}
\subsection{My sub section 1}
\section{My Section 2}

\cnta 0
\loop
  \advance\cnta 1
\subsection{My sub section \the\cnta}
  \ifnum\cnta<14
\repeat

\appendix
\chapter{My Annex}
\section{My Section 1}
\subsection{My sub section 1}
\section{My Section 2}

\cnta 0
\loop
  \advance\cnta 1
\subsection{My sub section \the\cnta}
  \ifnum\cnta<6
\repeat

\backmatter

\chapter{My back matter}
\section{My Section 1}
\subsection{My sub section 1}

\end{document}

extended toc

  • naturally Chapter should be Chapitre if the Table des matières heading is used.. just change the appropriate location in the chapter etoc style. –  Mar 06 '14 at 15:32
  • Or, even better, \@chapapp ;-) – karlkoeller Mar 06 '14 at 16:30
  • @karlkoeller good advice, but unfortunately this will not work inside the TOC to distinguish a Chapter (Chapitre, \chaptername) from an Annex (Annexe, \appendixname). But one can test if the "chapter" is numbered, if not then use \appendixname. I will update the code thanks. –  Mar 06 '14 at 16:59