2

I am using the book document class and I would like my customize my toc to look something like this:

custom toc mock-up

Lessons are actually chapters, renamed via:

\renewcommand{\chaptername}{Lesson}

They do not have titles, except for the exam every 10 lessons. I also have sections in the document which I don't want to show in the toc.

The ability to decide where to pagebreak would be nice for aesthetic purposes (for example, before 5 Pentagons) but it's not absolutely necessary.

I've looked into the tocloft package for this but so far I've not been able to do it properly.

1 Answer 1

4

enter image description here

\documentclass{book}

\makeatletter
\def\chaptername{lesson}
\renewcommand*\l@part[2]{\par
  \ifnum \c@tocdepth >-2\relax
    \addpenalty{-\@highpenalty}%
    \addvspace{2.25em \@plus\p@}%
    \setlength\@tempdima{3em}%
    \begingroup
      \parindent \z@ \rightskip \@pnumwidth
      \parfillskip -\@pnumwidth
      {\leavevmode
       \large \bfseries #1\hfil \hb@xt@\@pnumwidth{\hss #2}}\par
       \nobreak
         \global\@nobreaktrue
         \everypar{\global\@nobreakfalse\everypar{}}%
    \endgroup
  \fi
\par
\smallskip
\rightskip=0pt plus 2pt
\parfillskip=0pt}

\renewcommand\l@chapter[2]{%
\noindent\makebox[.3\linewidth][l]{%
\def\numberline##1{##1 }%
Lesson #1\dotfill#2}\penalty9000\hspace{.05\linewidth}\ignorespaces}



\makeatother

\begin{document}

\tableofcontents



\part{zzzz}
\chapter{aaa}aaa
\chapter{baaa}aaa
\chapter{baaa}aaa
\chapter{cbaaa}aaa
\chapter{dbaaa}aaa
\chapter{fbaaa}aaa
\chapter{gbaaa}aaa
\chapter{byaaa}aaa
\chapter{buaaa}aaa
\chapter{bajjaa}aaa
\chapter{ffbaaa}aaa
\chapter{fghbaaa}aaa

\part{www}
\chapter{tta}tta
\chapter{btta}tta
\chapter{btta}tta
\chapter{cbtta}tta
\chapter{dbtta}tta
\chapter{fbtta}tta
\chapter{gbtta}tta
\chapter{bytta}tta
\chapter{butta}tta
\chapter{bajjtt}tta
\chapter{ffbtta}tta
\chapter{fghbtta}tta

\end{document}
2
  • Thank you this is a big help, the only problem I have is that if the number of chapters in a part is 2 mod(3) then it looks like this: i.imgur.com/BMu618c.png Commented Mar 22, 2016 at 0:29
  • @TheFourthMan oops:-) Code updated with glue re-balanced. Commented Mar 22, 2016 at 9:21

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .