9

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?

Werner
  • 603,163
mapping
  • 225
  • 1
  • 2
  • 4

2 Answers2

11

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

Gonzalo Medina
  • 505,128
3
\documentclass[]{book}
\newcommand{\atoc}[1]{\addtocontents{toc}{#1\par}}
\renewcommand{\thesection}{\arabic{section}.}
\begin{document}
\tableofcontents

\section{Introduction}

\atoc{Part 1: the partition function}

\section{section 2}

\section{section 3}

\atoc{Part 2: theta function}

\section{section 4}

\end{document}

an image is attached enter image description here

Jesse
  • 29,686
  • 1
    While a workable solution, I would caution against using it as-is. Consider the following: it is possible (read likely) that you will want to change the style of how the parts appear in the table of contents when you are finished. This solution, as is, has you re-specifying every single addtocontents line to match the new format---a monotonous and error prone task. It would be better to place the line inside a newcommand that abstracts the idea of adding a TOC entry for the part. – Sean Allred Aug 22 '13 at 20:36
  • 1
    @Sean Points well taken. Something like \newcommand{\atoc}[1]{\addtocontents{toc}{#1\par}} and \atoc{Part 1: the partition function}. Appreciated. – Jesse Aug 22 '13 at 21:37