LaTeX Tips: Table of Contents as... a Table

Here I provide a minimal example of how to create a custom table of contents (ToC) in LaTeX which appears as a table. #latex

While experimenting with different ways of presenting some parts of LaTeX document I created a table of contents which looks as a table. See the illustration below:


This was possible with a package called etoc.

A preamble, nothing special here:





etoc allows to fully control how to typeset a ToC and even allows to specify which elements to display in the ToC. Let's say we introduce a custom sectioning level which we want to display as ToC. Somewhere in preamble we write:

% dummy sectioning level

Then we define a command which draws the ToC for us. We have to put it inside “group”:


 % body follows below


The following calls instruct etoc to handle only the section level we want:

  \etocglobaldefs% mandatory

  % mimics subsubsection

  \etocsetlevel{chapter}{99} % no chapters
  \etocsetlevel{section}{99} % no sections
  \etocsetlevel{subsection}{99} % no subsections
  \etocsetlevel{subsubsection}{99} % no subsections
  \etocsetlevel{part}{99} % no parts

For our custom section we set a style which in fact creates a table row for each entry:

    \etocnumber&\etocname&just text%

What remains is to set style for the whole ToC and write it. In ToC style definition we tell etoc to create a table:

      {\textcolor{white}{\textbf{number}}} &
      {\textcolor{white}{\textbf{name}}} &


The defined command can be places as usual in the document body:


Here is how we can fill our custom ToC:

\section{section 1}

\subsection{subsection 1}

\subsubsection{subsubsection 1}

\etoctoccontentsline{specialsection}{\protect\numberline{somenumber1} name 1}

\section{section 2}

\subsection{subsection 2}

\subsubsection{subsubsection 2}

\etoctoccontentsline{specialsection}{\protect\numberline{somenumber2} name 2}

\etoctoccontentsline operator ads an entry to the ToC.

Special quirk \protect\numberline{somenumber2} can be used (this is optionally) to set an entity which can later be referenced as \etocnumer when filling the table.

name 1 or name 2 strings can be referenced as \etocname.

That's it!