2

I'm sure this question has already been asked and answered but I didn't know what to look for in the forum.

I'd like to label my part title in TOC and in the beginning of the part itself like "First part", "Second part", etc.

What is the code for that?

2
  • Can you prepare a minimal example? Are you using \part in the document?
    – egreg
    Apr 18 '14 at 21:54
  • 1
    Now that I reread your question I have a doubt, you mean that \part{The title} should give you "First part: The title" both in the ToC and in the document (as in my answer) or is it something else what you are trying to achieve? Apr 19 '14 at 1:07
3

Two patchings to \@part (one for the entries in the ToC and the other for the headings in the document) will do the job; the fmtcount package was used to turn the Arabic number representation for the part counter to a ordinal string:

\documentclass{book}
\usepackage{xpatch}
\usepackage{fmtcount}

\makeatletter
\xpatchcmd{\@part}
  {\addcontentsline{toc}{part}{\thepart\hspace{1em}#1}}
  {\addcontentsline{toc}{part}{\Ordinalstring{part}~\partname:\hspace{0.5em}#1}}
  {}
  {}
\xpatchcmd{\@part}
  {\partname\nobreakspace\thepart}
  {\Ordinalstring{part}\nobreakspace\partname}
  {}
  {}
\makeatother

\begin{document}

\tableofcontents
\part{Test part}
\part{Another test part}
\part{Yet another test part}

\end{document}

An image of the ToC:

enter image description here

An image of the body og the document showing the heading for the first page:

enter image description here

1

Here is a solution using titlesec, titletoc and fmtcount, plus the \rmntonum command from etoolbox; we have to use it to convert the way part numbers appear in the .aux file (Roman numerals) to arabic.

\documentclass[english]{article}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{fourier}
\usepackage{microtype}
\usepackage{babel}
\usepackage{lipsum}

\usepackage{etoolbox}
\usepackage{fmtcount}

\usepackage[pagestyles, newparttoc]{titlesec}
\titleformat{\section}[hang]{\large\bfseries\boldmath}{§~\thesection}{0.6em}{\itshape}%
\titleformat{\part}[block]{\filcenter\lsstyle\bfseries\scshape\Large}{ \Ordinalstring{part} \partname: }{0.5em}{}%

\usepackage{titletoc}

\dottedcontents{section}[4em]{\bfseries}{1.85em}{1pc}%

\newsavebox{\partlabel}
\titlecontents{part}[1.5em]{\medskip\bfseries\renewcommand{\thepart}{\relax}}%
{\sbox{\partlabel}{\Ordinalstringnum{\expandafter\rmntonum\expandafter{\thecontentslabel}}~\partname: }%
\contentslabel[\usebox{\partlabel}]{0em}\hphantom{[\usebox{\partlabel}}}%
{\hspace*{0.06em}}%
{\hfill\contentspage}%
[\smallskip]%

\begin{document}

\tableofcontents{}

\part{An Interesting Part}
\lipsum[1-2]
\section{A First Section}
\lipsum[1-10]
\section{A Second Section}
\lipsum[1-10]
\part*{A Boring Numberless Part}
\lipsum[1]
\section{Section A}
\lipsum[1]
\section{Section B}
\lipsum[1]
\part{Another Numbered Part}

\end{document} 

enter image description here

0

I guess you want to avoid the automatic "Part I" (et cetera). You can remove it with \renewcommand{\partname}{} (in the preamble) - though the roman number will remain.

A MWE:

\documentclass{book}
\renewcommand{\partname}{}
\begin{document}
\tableofcontents
\part{First Part}
\chapter{some title}
\newpage
\chapter{another one}
\part{Second Part}
\end{document}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.