TransWikia.com

Render a table of contents like an itemize list

TeX - LaTeX Asked by Michael Marx on January 18, 2021

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}{itemgdefcontentslineused{}}{}{}
renewcommand{tableofcontents}{
    subsection*{Agenda}
    begin{itemize}
        @starttoc{toc}
        ifcsname contentslineusedendcsnameelse
            item Agenda
        fi
    end{itemize}
}
makeatother

2 Answers

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]{#1quad}% 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
  #1dotfill #2
}
pretocmd{contentsline}{itemgdefcontentslineused{}}{}{}
renewcommand{tableofcontents}{%
  begin{itemize}
    @starttoc{toc}
    ifcsname contentslineusedendcsnameelse
      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.

Correct answer by Werner on January 18, 2021

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 renewcommandcftsecpagefont{@gobble}.

documentclass{article}

usepackage{tocloft}
setcounter{tocdepth}{1} % optional
renewcommandcontentsname{Agenda}
renewcommandcfttoctitlefont{normalsizebfseries} % default: Largebfseries
renewcommandcftsecfont{mdseries} % default is bfseries
setlengthcftsecnumwidth{1em}
makeatletter
renewcommandcftsecpresnum{textbullet@gobble} % don't show section numbers
renewcommandcftsecpagefont{@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}

Answered by Mico on January 18, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP