[Tex/LaTex] How to get a very compact TOC

table of contents

enter image description here

This is how the original TOC looks.

This original format of the table of contents takes too much space. I wanted some format that is compact and found this sample.

I am also searching for other nicer looking formats that are compact. For example

enter image description here

Best Answer

The titletoc can achieve this though the \titlecontents command. The starred version places all the titles on the same paragraph.

The command isn't the most user friendly to use, so I tried to annotate as best as I could.

\documentclass{book}

\usepackage{titletoc}
\titlecontents{chapter}             % Section
  [0em]                             % Left
  {\vspace*{\baselineskip}}         % Above code
  {\bfseries\thecontentslabel\quad} % Numbered format
  {}                                % Numberless format
  {\quad\thecontentspage}           % Filler
  []                                % Separator
\titlecontents*{section} % Section
  [0em]                  % Left
  {\space}               % Above code
  {\thecontentslabel~}   % Numbered format
  {}                     % Numberless format
  {}                     % Filler
  [.\space]              % Separator
\titlecontents*{subsection} % Section
  [0em]                     % Left
  {\space}                  % Above code
  {}                        % Numbered format
  {}                        % Numberless format
  {}                        % Filler
  [.\space]                 % Separator

\begin{document}

\tableofcontents

\clearpage

\chapter{Introduction}

\chapter{The Principle of Locality in Classical Physics and the Relativity Theories}

\subsection{Faraday's vision}
\subsection{Fields}

\section{Special relativity}

\subsection{Poincar\'e group}
\subsection{Lorentz group}
\subsection{Spinors}
\subsection{Conformal group}

\section{Maxwell theory}

\section{General Relativity}

\chapter{Poincar\'e Invariant Quantum Theory}

\section{Geometric symmetries in quantum physics}
\subsection{Projective representations and the covering group}

\section{Wigner's analysis of irreducible, unitary representation of the Poincar\'e group}

\section{Single particle states}
\subsection{Spin}

\section{Many particle states: Bose--Fermi alternative, Fock space, creation operators}
\subsection{Separation of CM-motion}
\end{document}

output

An important thing to note is that due to the way the table of contents is generated, LaTeX struggles to create line breaks. In order to allow line breaks between successive elements, I have added \space in the above code and also in the separator. Do not use ~ as this is creates a space that cannot break across lines. The only time I have used ~ is between the a section's number and its title in order to avoid:

... Faraday's vision. Fields. 2.1

Special relativity. Poincare ...

Related Question