The book "One thousand exercises in probability" (Grimmett, Stirzaker) has a very nice table of contents:
As it looks like, the book only consists of chapters: First, all exercise chapters (including sections) appear, then the corresponding solutions (with the same chapter/section structure). I reset the chapter numbering (see below) to reflect that, but how can one create a table of contents as shown above?
Here is a basic template:
\documentclass{scrbook}
\usepackage[american]{babel}
\begin{document}
\tableofcontents
\chapter{Chapter 1}
\section{Section 1}
\section{Section 2}
\section{Section 3}
\clearpage
\setcounter{chapter}{0}
\chapter{Solutions to Chapter 1}
\section{Solutions to Section 1}
\section{Solutions to Section 2}
\section{Solutions to Section 3}
\end{document}
Best Answer
A bit hacky, but it gives the desirable result... Currently, it's still required to manually add the label per each solution section. It would be desirable if this also could be automated.
Removes all table of contents entries of any level from this line. You'll have to change this behavior back if you want for example appendices to appear in the toc after this line.
Overall, the idea is to redefine the format of the table of contents. Add manually a cross-reference to the section label. And manually add the label. There is most certainly a more gracious way of doing this, though.
Edit: Added a manual fix for the
hyperref
package. Manually ahypertarget
is added by the new defined\sectionsol
command, which defines both the target and a label. Finally, ahyperlink
is added in the toc, which points to the hypertarget.Edit: Copied over the adjusted solution by Marius Hofert, which has better spacing. And to save it in case a better solution comes along.
When using the
mathtools
package the\setcounter
macro has to be protected. See this answer for more details.