4

I want to add the word "Part" before my entries in the toc.

I read here that I could use \renewcommand\cftpartpresnum{Part~}. I have tried adding making some modifications to the partpresnum and partleader command but it did not work.

I am using the classicthesis style, which defines the toc like this for parts: (The full style file can be seen here)

    \ifthenelse{\boolean{@parts}}%
    {%
      \renewcommand{\thepart}{\roman{part}}%
      \renewcommand{\cftpartpresnum}{\scshape}%  \MakeTextLowercase
%      \renewcommand{\cftpartaftersnum}{\cftchapaftersnum}%
%      \renewcommand{\cftpartaftersnumb}{\quad}%
%      \setlength{\cftpartnumwidth}{\cftpartnumwidth}
      \renewcommand{\cftpartfont}{\color{Maroon}\normalfont}%
      \renewcommand{\cftpartpagefont}{\normalfont}%
      \ifthenelse{\boolean{@dottedtoc}}{\relax}%
      {%
        \renewcommand{\cftpartleader}{\hspace{1.5em}}% 
        \renewcommand{\cftpartafterpnum}{\cftparfillskip}%
      }%        
      \setlength{\cftbeforepartskip}{1em}%
      \setlength{\cftbeforechapskip}{.1em}%
      \setlength{\beforebibskip}{\cftbeforepartskip}%
     }{\relax}
    % chapters
    \ifthenelse{\boolean{@nochapters}}%
        {\relax}%
        {%
            \renewcommand{\cftchappresnum}{\scshape\MakeTextLowercase}%
            \renewcommand{\cftchapfont}{\normalfont}%
            \renewcommand{\cftchappagefont}{\normalfont}%
            \ifthenelse{\boolean{@dottedtoc}}{\relax}%
                {%
                \renewcommand{\cftchapleader}{\hspace{1.5em}}% 
                \renewcommand{\cftchapafterpnum}{\cftparfillskip}% 
            }
            %\setlength{\cftbeforechapskip}{.1em}%           
        }

... see style file for full code.

Any suggestions? Am I trying to make changes in the right place even?

The following is a reduced example. I tried using only a portion of the style file, but I couldn't get that working.

\documentclass[parskip=half,10pt,twoside]{scrbook}
\usepackage{classicthesis}


\begin{document}

\tableofcontents
\part{First test part}
\chapter{Test chapter}
\chapter{Test chapter}
\part{Second  test part}
\chapter{Test chapter}
\chapter{Test chapter}

\end{document}
dorien
  • 1,615
  • 1
    Please help us to help you and add a minimal working example (MWE) that illustrates your problem. It will be much easier for us to reproduce your situation and find out what the issue is when we see compilable code, starting with \documentclass{...} and ending with \end{document}. As such, your example is something 'cut out' and users have to apply their chrystal ball in order to guess what comes before and after it ;-) –  Jul 02 '14 at 10:54
  • I have added a reduced example. You do need the external style file though. – dorien Jul 02 '14 at 13:34

1 Answers1

3

Since classicthesis uses the tocloft package internally to generate the ToC, adding a "Part~" string can be achieved with the following code (assuming that your LaTeX installation has the latest version of the tocloft package):

\renewcommand{\cftpartpresnum}{Part~}

\newlength{\mylen} % a "scratch" length
\settowidth{\mylen}{\cftpartpresnum} % extra space
\addtolength{\cftpartnumwidth}{\mylen} % add the extra space

Notice that by redefining the \cftpartpresnum command to prepend the "Part~" string, we are adding text to the number box in addition to the part number. Thus, we need to increase the width of the box to include the additional text. One possible method is to create a new length that will store the width of the additional text and add the extra space to the \cftpartnumwidth macro.

enter image description here

EDIT: I'm adding the full code (based on the provided MWE) that produces the desired results. In addition, the tocloft package I used (v2.3f, 2013/05/02) is downloaded from here.

\documentclass[parskip=half,10pt,twoside]{scrbook}
\usepackage{classicthesis}

\renewcommand{\cftpartpresnum}{Part~}

\newlength{\mylen} % a "scratch" length
\settowidth{\mylen}{\cftpartpresnum} % extra space
\addtolength{\cftpartnumwidth}{\mylen} % add the extra space

\begin{document}

\tableofcontents
\part{First test part}
\chapter{Test chapter}
\chapter{Test chapter}
\part{Second  test part}
\chapter{Test chapter}
\chapter{Test chapter}

\end{document}

NOTE: For earlier versions of the tocloft package the documentation states that using it together with the KOMA classes (and others) might result in \cftpartpresnum becoming doubled in the output. This behavior is fixed (at least) since version 2.3f.

EDIT 2: Passing the parts option to the classicthesis package seems to disable this workaround. The reason is that, when using this option, the classicthesis class relies on the titlesec package in order to produce the ToC entry for parts. Luckily, the documentation for the package states that:

  • \part does not encapsulates the label in the toc entry, except if you use the newparttoc option. [page 10]

and the description for the option itself further adds:

Standard parts write the toc entry number in a non standard way. You may change that with newparttoc so that titletoc or a similar package can manipulate the entry. (That works only if \part has been redefined.) [page 8]

Thus, to get the desired behavior, it's simply a matter of passing this option to the titlesec package with \PassOptionsToPackage{newparttoc}{titlesec}, prior to loading the classicthesis package.

The final code looks like this:

\documentclass[parskip=half,10pt,twoside]{scrbook}
\PassOptionsToPackage{newparttoc}{titlesec} % MUST be called before classicthesis
\usepackage[dottedtoc,floatperchapter,parts]{classicthesis}

\renewcommand{\cftpartpresnum}{Part~}

\newlength{\mylen} % a "scratch" length
\settowidth{\mylen}{\cftpartpresnum} % extra space
\addtolength{\cftpartnumwidth}{\mylen} % add the extra space

\begin{document}

\tableofcontents
\part{First test part}
\chapter{Test chapter}
\chapter{Test chapter}
\part{Second  test part}
\chapter{Test chapter}
\chapter{Test chapter}

\end{document}

and the output produced: enter image description here

  • I tried this, but it does not do anything. Could it be because of the version issue? – dorien Aug 01 '14 at 14:22
  • I have version 2013.72.2.3fsvn30209-11.2.1 – dorien Aug 01 '14 at 14:44
  • @dorien It works fine for me with the latest tocloft package (version 2.3f). What do you mean with "it does not do anything?" – Alberto Miranda Aug 06 '14 at 09:26
  • The toc is still the same. Could it be that the template is overwriting it? – dorien Aug 20 '14 at 11:13
  • 1
    I updated the answer with a full MWE that gives the desired results (on my installation). Can you check if this works on your installation? Also, can you double-check that the tocloft package you're using is the same as the one in the link I provided? – Alberto Miranda Aug 20 '14 at 13:48
  • Thank you. The problem seems to be because I load classicthesis with: \usepackage[dottedtoc,floatperchapter,parts]{classicthesis}. Especially the parts option does this. I do need it however for the nice parts layout. So I'm guessing I need to change something in the classicthesis style. – dorien Aug 22 '14 at 11:04
  • 1
    There's no need to tinker with the classicthesis style. I updated the answer to include a workaround for the parts option. This will hopefully fulfill your requirements :) – Alberto Miranda Aug 22 '14 at 14:11
  • Getting closer. This works on the template, but on my full document the main memory is exceeded. I've already expanded the memory, but it keeps exceeding it. Strange. – dorien Aug 22 '14 at 19:57
  • It would appear that this in my preamble is producing the error:\hypersetup{ colorlinks=true, linktocpage=true, pdfstartpage=1, pdfstartview=FitV, breaklinks=true, pdfpagemode=UseNone, pageanchor=true, pdfpagemode=UseOutlines,% plainpages=false, bookmarksnumbered, bookmarksopen=true, bookmarksopenlevel=1, hypertexnames=true, pdfhighlight=/O, urlcolor=webbrown, linkcolor=RoyalBlue, citecolor=webgreen, } – dorien Aug 22 '14 at 21:28
  • More specifically, the bookmarksnumbered seems to be causing an incompatibility. Perhaps I can just do without this option. Let me check! That would be awesome :) – dorien Aug 22 '14 at 21:33