2

I write some short reports with the article class, and I would like to have a minimalist table of contents, which would be rendered like an itemized list. To be more specific, I would like to have a rendering similar as this one (but with clickable titles) for the table of contents of an article with three sections.

\subsection*{Agenda}

\begin{itemize} \item First section \item Second section \item etc \end{itemize}

Is it possible to easily get such a result? Thank you in advance!

Edit: Thank you for your answers! Here is the code I used.

\makeatletter
\renewcommand{\numberline}[1]{}  % Removes the section numbers in the ToC
\renewcommand{\l@section}[2]{#1}  % #1 = section number + title; #2 = page number
\pretocmd{\contentsline}{\item\gdef\contentslineused{}}{}{}
\renewcommand{\tableofcontents}{
    \subsection*{Agenda}
    \begin{itemize}
        \@starttoc{toc}
        \ifcsname contentslineused\endcsname\else
            \item Agenda
        \fi
    \end{itemize}
}
\makeatother

2 Answers2

2

Here's a solution that employs the machinery of the tocloft package.

enter image description here

I interpreted your write-up as not wanting to show the page numbers; if this interpretation is incorrect, simply omit (or comment out) the instruction \renewcommand\cftsecpagefont{\@gobble}.

\documentclass{article}

\usepackage{tocloft} \setcounter{tocdepth}{1} % optional \renewcommand\contentsname{Agenda} \renewcommand\cfttoctitlefont{\normalsize\bfseries} % default: \Large\bfseries \renewcommand\cftsecfont{\mdseries} % default is \bfseries \setlength\cftsecnumwidth{1em} \makeatletter \renewcommand\cftsecpresnum{\textbullet@gobble} % don't show section numbers \renewcommand\cftsecpagefont{@gobble} % don't show page numbers \makeatother

\usepackage[colorlinks,allcolors=blue]{hyperref} % choose a suitable color

\begin{document} \tableofcontents

\section{First} \section{Second} \section{Third} \end{document}

Mico
  • 506,678
  • Thanks ! I like your code, however I preferred the other one cause the bullet is not included in the link (I personally find it more aesthetic). – Michael Marx Oct 17 '20 at 11:54
  • @MichaelMarx - If you had asked about how one might change the color of the text bullet, I could have let you know that all you'd have to do was to replace \textbullet with {\color{black}\textullet}. – Mico Oct 17 '20 at 13:39
  • In fact, I was thinking about the box that defines the link to the section. The bullet is included in the clickable frame, as if it is part of the link, and I find it a bit confusing. I chose the other answer because I find it more straighforward (as it defines epxlicitly an itemize), so I could more easily figure how to customize it. :) – Michael Marx Oct 18 '20 at 11:31
1

The following code prints the \tableofcontents as an itemized list. I've removed the numbering of the \sections by making \numberline do nothing with it's argument (the section number). Note that you'll have to manually insert sections' titles into the ToC if you're using \section* (see Adding unnumbered sections to ToC). Of course, you can update the way \section functions to do that automatically, based on your setup.

enter image description here

\documentclass{article}

\usepackage{hyperref,etoolbox}

\makeatletter %\renewcommand{\numberline}[1]{#1\quad}% Keeps the section numbers in the ToC \renewcommand{\numberline}[1]{}% Removes the section numbers in the ToC \renewcommand{\l@section}[2]{% #1 = section number + title; #2 = page number #1\dotfill #2 } \pretocmd{\contentsline}{\item\gdef\contentslineused{}}{}{} \renewcommand{\tableofcontents}{% \begin{itemize} @starttoc{toc} \ifcsname contentslineused\endcsname\else \item Table of Contents \fi \end{itemize} } \makeatother

\begin{document}

\subsection*{Agenda}

\tableofcontents

\section{First section} \section{Second section} \section{Third section} \section{Final section}

\end{document}

The conditional syntax within the newly-defined \tableofcontents is to avoid a first-time compile when there is no ToC yet. It'll print a list with a single item Table of Contents when there is no ToC, and the actual ToC after another compilation.

Werner
  • 603,163
  • I tried this code, but it throws an error: ! LaTeX Error: Something's wrong--perhaps a missing \item. However, it works if I add a \item test just after the \begin{itemize} for example. – Michael Marx Oct 16 '20 at 21:56
  • @MichaelMarx: Right... I already had a ToC file while I was working on the code, so forgot to check for the existence of a .toc. I've updated the code to accommodate for that. – Werner Oct 17 '20 at 03:45
  • Thank you! I just updated my post with the final code I used. :) – Michael Marx Oct 17 '20 at 12:01