2

In his TeXbook, Donald Knuth creates a very beautiful crosshatch pattern for the leaders in the Table on Contents.

Crosshatch patter for leading dots in table of contents

I tried mimicking it with the package tocloft, using an complicated scheme of an alternating white/black dots that switch colors when the lines change, but it was overly messy and unsatisfying, and the result was not fully identical.

How can we accomplish this design in LaTeX in a simple and elegant way?

1

Here is one. The code for \diamondleaders is lifted directly from texbook.tex (ll. 304-308) and has been slightly adapted.

We just need tocloft to use the new leaders and we are good to go.

\documentclass[british]{article}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{babel}
\usepackage{blindtext}
\usepackage{tocloft}

\setcounter{tocdepth}{1}
\renewcommand{\cftsecleader}{\diamondleaders\hfil}

\newcount\diamondswitch
\newcommand*{\diamondleaders}{%
  \global\advance\diamondswitch by 1
  \ifodd\diamondswitch \kern-10pt \fi
  \leaders\hbox to 20pt{\ifodd\diamondswitch \kern13pt \else\kern3pt \fi
    .\hss}}

\begin{document}
\tableofcontents
\Blinddocument
\blinddocument
\Blinddocument
\end{document}

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.