[Tex/LaTex] Add “Parts” to the Table of Contents

partstable of contents

I want to have a table of contents as follows:

1. Introduction

Part 1: the partition function

2. section 2

3. section 3

Part 2: theta function

4. section 4

How can I do this?

Best Answer

You can use the tocloft package to add the string "Part" to the entries in the ToC; I used

\@addtoreset{section}{part}
\renewcommand\thepart{\arabic{part}}

so the the section counter is reset in each new part and the part counter uses Arabic numbers.

\documentclass{article}
\usepackage{tocloft}

\makeatletter
\@addtoreset{section}{part}
\makeatother
\newlength\mylen
\renewcommand\thepart{\arabic{part}}
\renewcommand\cftpartpresnum{Part~}
\settowidth\mylen{\bfseries\cftpartpresnum\cftpartaftersnum}
\addtolength\cftpartnumwidth{\mylen}

\begin{document}

\tableofcontents
\section{Introduction}
\part{First test part}
\section{Test section}
\section{Test section}
\part{Second  test part}
\section{Test section}
\section{Test section}

\end{document}

enter image description here