3

Following on my previous question here, I would now like to add the string "Part" to the TOC.

Using a modified thesis style and \documentclass{report} which dictates how the TOC appears. I have tried other solutions presented in other questions, but these do not seem to work.

I am currently using:

\usepackage{fmtcount} \renewcommand{\thepart}{\Numberstring{part}}

to change the \part numbering to a numberstring "One" "Two" etc. I would like the string "Part" to appear in the TOC. Instead of:

One Some title here

Is there a way to get the TOC listing to be:

Part One Some title here

??

1

Assuming, the "modified thesis style" is the same as in your previous question and therefore does not change the definition of "part" and that your document uses the original \@part definition from report.sty:

\def\@part[#1]#2{\ifnum \c@secnumdepth >-2\relax
        \refstepcounter{part}%

        \addcontentsline{toc}{part}{\thepart
        \hspace{1em}#1}\else

        \addcontentsline{toc}{part}{#1}\fi
   \markboth{}{}%
   {\centering
    \interlinepenalty \@M
    \ifnum \c@secnumdepth >-2\relax
      \huge\bf \partname~\thepart
    \par
    \vskip 20\p@\fi
    \Huge \bf
    #2\par}\@endpart}

then including

\makeatletter
\def\@part[#1]#2{\ifnum \c@secnumdepth >-2\relax
        \refstepcounter{part}%

        \addcontentsline{toc}{part}{Part \thepart
        \hspace{1em}#1}\else

        \addcontentsline{toc}{part}{#1}\fi
   \markboth{}{}%
   {\centering
    \interlinepenalty \@M
    \ifnum \c@secnumdepth >-2\relax
      \huge\bf \partname~\thepart
    \par
    \vskip 20\p@\fi
    \Huge \bf
    #2\par}\@endpart}
\makeatother

in your document will work.

I set up an example of how this works at writeLaTeX. (lines 284-299)

Output

  • 1
    Voila! It does work- it didn't the first time I tried it (after two PDFlatex runs), but after looking at your example code at writeLaTeX, adding the code right before \makeatother (then two more PDFlatex runs), it then seemed to work fine. – charles Jul 29 '14 at 18:29
  • ps. subtle with the Part titles ;) – charles Jul 29 '14 at 18:30
  • Glad it worked. And always remember - including an MWE makes it much easier for the folks at TeX.SX to work on your question. ;) – Sora. Jul 29 '14 at 18:31
  • Probably why you were the only one to answer having slogged through the MWE in my previous question! – charles Jul 29 '14 at 18:33
1

You also can do that with titlesec/titletoc.

Specifically, for the case of \part, it requires its formatting to be redefined with \titleformat and choosing the newparttoc option when loading titlesec.

Here is an example:

\documentclass{book}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{lmodern}

\usepackage[english]{babel}
\usepackage[newparttoc,explicit, clearempty]{titlesec}%
\usepackage{titletoc}
\usepackage{chngcntr}
\usepackage{fmtcount}
\counterwithin*{chapter}{part}
\usepackage{etoolbox} 

\def\partname{Part}

\renewcommand\thepart{\NUMBERstring{part}}%
\titleformat{\part}[display]{\bfseries\filcenter}{\huge\partname~\thepart}{20pt}{\Huge #1}[\thispagestyle{empty}]%

\titlecontents{part}[0em]{\large\bfseries\protect\addvspace{25pt}\titlerule\addvspace{1.5ex}}%
{\contentslabel[\rlap{\partname~\thecontentslabel}]{0em}\hphantom{\partname~\thecontentslabel\quad}}{}%
{,\quad\contentspage}[\addvspace{1ex}\titlerule\addvspace{1ex}]%

\begin{document}

\tableofcontents

\part{A First Part}
\chapter{Chapter the First}
\section{Section 1.1}
\section{Section 1.2}

\chapter{Chapter the Second}
\section{Section 2.1}
\section{Section 2.2}

\part{Another Part} \label{part-2}

\chapter{Chapter the First}
\section{Section 1.1}
\section{Section 1.2}

\chapter{Chapter the Second}
\section{Section 2.1}
\section{Section 2.2}

\end{document} 

enter image description here

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.