7

I really enjoy the table of contents formatting (all sections of a chapter in a single paragraph), of the Motion Mountain's physics books. Does anyone know how to reproduce that kind of style? Is there a LaTeX package for managing TOC styles?

BTW, I need to use XeLaTeX, and it seems to exist an incompatibility between 'fontspec' and 'titletoc'.

lockstep
  • 250,273

1 Answers1

7

The tocloft and titletoc packages let you customize the table of contents. In your case, the second package could be a better choice: the starred version of \titlecontents groups the entries in a single paragraph.

Here's a little example (of course, feel free to adapt it according to your needs):

\documentclass{scrbook}
\usepackage{titletoc}

\titlecontents{chapter}[0pt\addvspace{15pt}]
{\llap{\makebox[3em]{\oldstylenums{\thecontentspage\hfill\thecontentslabel}}\hskip1em}
  \small\scshape\vskip-\baselineskip}{}{}{}
\titlecontents*{section}[20pt]
{\upshape}{}{}
{, \oldstylenums{\thecontentspage}}[][\ \textbullet\ ][]

\begin{document}

\tableofcontents
\chapter{Test chapter one}
\section{Test section one one}
\section{Test section one two}
\section{Test section one three}
\section{Test section one four}
\section{Test section one five}
\chapter{Test chapter two}
\section{Test section two one}
\section{Test section two two}
\section{Test section two three}

\end{document}

The resulting ToC:

enter image description here

EDIT: as Alan Munn noticed in a comment, the above example fails to compile with fontspec and xelatex, due to the \addvspace{15pt} command in the first optional argument of \titlecontents{chapter}; a possible workaround would be to introduce the vertical skip in the second mandatory argument of \titlecontents:

\documentclass{scrbook}
\usepackage{fontspec,xltxtra}
\usepackage{titletoc}

\titlecontents{chapter}[0pt]
{\vskip15pt\llap{\makebox[3em]{\oldstylenums{\thecontentspage\hfill\thecontentslabel}}\hskip1em}
  \small\scshape\vskip-\baselineskip}{}{}{}
\titlecontents*{section}[20pt]
{\upshape}{}{}
{, \oldstylenums{\thecontentspage}}[][\ \textbullet\ ][]

\begin{document}

\tableofcontents
\chapter{Test chapter one}
\section{Test section one one}
\section{Test section one two}
\section{Test section one three}
\section{Test section one four}
\section{Test section one five}

\chapter{Test chapter two}
\section{Test section two one}
\section{Test section two two}
\section{Test section two three}

\end{document}
Gonzalo Medina
  • 505,128
  • Nice... But it seems to be incompatible with fontspec and xelatex? For example, by adding: \usepackage{fontspec,xltxtra} \setmainfont[Mapping=tex-text]{Hoefler Text} – Hugo Sereno Ferreira Jul 31 '11 at 02:12
  • Damn: http://www.macfreek.nl/mindmaster/LaTeX_package_conflicts#XeTeX_and_titletoc – Hugo Sereno Ferreira Jul 31 '11 at 02:19
  • @Hugo S Ferreira: indeed, there seems to be an incompatibility and I don't know a workaround. I'll try to think of something. Perhaps you should add the information to your question (about you using XeLaTeX and fontspec). – Gonzalo Medina Jul 31 '11 at 02:28
  • @Hugo Interestingly, it doesn't work even if I remove the titletoc stuff. Without a bug report (please, do) it's difficult to say where the problem is. As to the link, note it says \vspace{3px} and the error is what you could expect, since px is not a unit in TeX or XeTeX. – Javier Bezos Aug 05 '11 at 14:26
  • 2
    The error is caused by the \addvspace{15pt} command in the \titlecontents{chapter} command. That's the minimal document that fails. – Alan Munn Aug 08 '11 at 17:01
  • @Hugo S Ferreira: I've updated my answer (see Alan's comment). – Gonzalo Medina Aug 08 '11 at 21:01
  • Thank you! I've awarded the bounty, although I think Alan should have had a share of it :-) – Hugo Sereno Ferreira Aug 08 '11 at 21:23
  • @Gonzalo Do you have any idea why it fails inside the optional argument? The titletoc code is quite complicated and I couldn't figure out a reason. (@Hugo: Thanks for the kind words. I'm just happy to have helped.) – Alan Munn Aug 08 '11 at 21:31
  • @Alan: no idea. The error message produced by the original code comes from the calc package. From the documentation I got "After a value has been read, \calc@post@scan is called, and expects a binary operator, a sequence of right parentheses, a ! character, or \relax." Obviously, \addvspace is not one of the expected tokens and this triggers the error message, but then I wonder why it works OK without fontspec. We'll have to ask Javier. – Gonzalo Medina Aug 09 '11 at 00:05