6

I'm using the code below for my \part heading style. I want to be able to modify what appears in ToC as my part name. Possibly put a different text there and also modify its font style (size, shape etc.). What should I modify in my code?

\documentclass[draft]{book}
\usepackage[table]{xcolor}
\usepackage{epigraph}
\setlength\epigraphwidth{.6\textwidth}

\makeatletter
\def\@part[#1]#2{%
\ifnum \c@secnumdepth >-2\relax
 \thispagestyle{epigraph}
  \refstepcounter{part}%
  \addcontentsline{toc}{part}{\partname~\thepart:\hspace{1em}#1}%
\else
  \addcontentsline{toc}{part}{#1}%
\fi
\markboth{}{}%
  \reset@font
  \parindent \z@ 
  \vspace*{-400\p@}%
  \hbox{%
    \vbox{%
      \hsize=7mm%
     \makebox(0,0){\put(10,-100){\fbox{\phantom{\rule[-4cm]{7mm}{4cm}}}}}%
 \begin{tabular}{@{}p{7mm}@{}}
    \makebox[7mm]{\scshape\strut\small\partname}\\
    \makebox[7mm]{\cellcolor{gray}\Huge\color{white}\bfseries\strut\thepart\rule[-4cm]{0pt}{4cm}}%
  \end{tabular}%
  }%
\kern6pt
\vbox to 0pt{%
   \tabular[t]{@{}p{1cm}>{\raggedright\arraybackslash}p{\dimexpr\hsize-2.55cm}@{}}\hline
      & \Huge\itshape\rule{0pt}{1.5\ht\strutbox}#1\endtabular}%
}%
  \cleardoublepage

}
\makeatother

\begin{document}

\tableofcontents
\cleardoublepage

\epigraphhead[450]{Fairy tales are more than true: not because they tell us that dragons exist, but because they tell us dragons can be beaten.\par\hfill\textsc{C.K. Chesterton}}
\part{A Test Part Title}

\end{document}
3

You can use the usual interface to specify a different <ToC title> to your <part title>:

\part[<ToC title>]{<part title>}

If you wish to adjust the font (and other characteristics) of the ToC-related entries, consider using tocloft. For example, using

\usepackage{tocloft}
\renewcommand{\cftpartfont}{\itshape\LARGE}

prints the ToC-entry associated with a \part in \itshape\LARGE font.

3
  1. The standard way to have different contents for the actual heading and the entry in the ToC is to use the optional argument of the sectional unit, as Werner mentioned in his answer:

    \part[Titlte for the ToC]{Title for the document}
    

    this, however, won't work in your actual code due to a mistake in the redefinition of \@part to produce the special formatting; the problem was that the definition in your code was using the wrong parameter #1 instead of the appropriate #2 in the snippet in charge of the actual heading typesetting:

    \tabular[t]{@{}p{1cm}>{\raggedright\arraybackslash}p{\dimexpr\hsize-2.55cm}@{}}\hline
    & \Huge\itshape\rule{0pt}{1.5\ht\strutbox}#1\endtabular}%
    

    In the example code below I've fixed this.

  2. You don't need anymore packages to do this, since \@part is also in charge of the ToC entry. Below I introduced a \partfont commands used to change the font attributes for the part entries:

    \ifnum \c@secnumdepth >-2\relax
     \thispagestyle{epigraph}
      \refstepcounter{part}%
      \addcontentsline{toc}{part}{\parttocfont\partname~\thepart:\hspace{1em}#1}%
    \else
      \addcontentsline{toc}{part}{\parttocfont#1}%
    \fi
    

    The default definition I used was

    \def\parttocfont{\normalfont\Large\scshape}
    

    to have the entries in \Large size and small-caps but, of course, you can change this to suit your needs.

The complete code:

\documentclass{book}
\usepackage[table]{xcolor}
\usepackage{epigraph}
\setlength\epigraphwidth{.6\textwidth}

\def\parttocfont{\normalfont\Large\scshape}

\makeatletter
\def\@part[#1]#2{%
\ifnum \c@secnumdepth >-2\relax
 \thispagestyle{epigraph}
  \refstepcounter{part}%
  \addcontentsline{toc}{part}{\parttocfont\partname~\thepart:\hspace{1em}#1}%
\else
  \addcontentsline{toc}{part}{#1}%
\fi
\markboth{}{}%
  \begingroup
  \reset@font
  \parindent \z@ 
  \vspace*{-400\p@}%
  \hbox{%
    \vbox{%
      \hsize=7mm%
     \makebox(0,0){\put(10,-100){\fbox{\phantom{\rule[-4cm]{7mm}{4cm}}}}}%
 \begin{tabular}{@{}p{7mm}@{}}
    \makebox[7mm]{\scshape\strut\small\partname}\\
    \makebox[7mm]{\cellcolor{gray}\Huge\color{white}\bfseries\strut\thepart\rule[-4cm]{0pt}{4cm}}%
  \end{tabular}%
  }%
\kern6pt
\vbox to 0pt{%
   \tabular[t]{@{}p{1cm}>{\raggedright\arraybackslash}p{\dimexpr\hsize-2.55cm}@{}}\hline
      & \Huge\itshape\rule{0pt}{1.5\ht\strutbox}#2\endtabular}%
}%
  \endgroup
  \cleardoublepage

}
\makeatother

\begin{document}

\tableofcontents
\cleardoublepage

\epigraphhead[450]{Fairy tales are more than true: not because they tell us that dragons exist, but because they tell us dragons can be beaten.\par\hfill\textsc{C.K. Chesterton}}
\part[The title for the ToC]{A Test Part Title}

\end{document}

An image of the ToC:

enter image description here

An image of the actual heading:

enter image description here

  • awesome, thank you so much. Looks like right now, the properties we apply for the font in TOC, doesn't hold for the number in front of it, right? For instance they don't get bold together ... How can we make then act similarly? – LatexQuest Jul 28 '14 at 8:43
  • I think there should be another problem with the code. Is there any global parameter that affects the paragraph indentation? Because only when I use this code, my paragraph indentations will be gone. – LatexQuest Jul 28 '14 at 9:41
  • 1
    @LatexQuest you're right about the indentation; I've fixed this in my updated answer. Regarding the other question, I'll provide the necessary code later. – Gonzalo Medina Jul 28 '14 at 13:57
  • 1
    @LatexQuest I did some tests. and the definitions used in \parttocfont affect all the entry. For example, using \def\parttocfont{\normalfont\Large\bfseries} makes all the entry \Large and boldfaced. Perhaps you are using a combination of font attributes that is not defined in the font used? I mean, if you try \def\parttocfont{\normalfont\Large\scshape\bfseries} with the default font, you won't get small caps because the default font doesn't provide small caps in bold faced series. – Gonzalo Medina Jul 28 '14 at 14:06
  • My observation is that when I use your code "exactly", the number is bold but the rest (title in TOC) is not. So, I had to modify it to `\def\parttocfont{\normalfont\bfseries\normalsize\scshape}' to make both bold. Still I think the font size of number and title in not the same! – LatexQuest Jul 28 '14 at 14:46

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.