How to customise font size of Table of Contents generated by package{tocloft} in LATEX

latex

I am using document class "report" and package {tocloft}. I am having a problem in changing font size of sections, chapters, subsections explicitly on Table of Contents generated by "\tableofcontents". It is actually taking the size of contents as they are present in report but I want to alter the font size of table of contents page .

\documentclass{report}

\usepackage{tocloft,lipsum,pgffor}

\setcounter{tocdepth}{3}% Include up to \subsubsection in ToC

\renewcommand{\cftpartfont}{\normalfont\sffamily\bfseries}% \part font in ToC
\renewcommand{\cftchapfont}{\normalfont\large\itshape}    % \chapter font in ToC
\renewcommand{\cftsecfont}{\normalfont\slshape}           % \section font in ToC
\renewcommand{\cftsubsecfont}{\normalfont\itshape}        % \subsection font in ToC
\renewcommand{\cftsubsubsecfont}{\normalfont\small}       % \subsubsection font in ToC

\begin{document}

\tableofcontents% ToC

% Create a dummy document with multiple (5) levels of sectional units
\foreach \curpart in {\Huge First, Second, Third, Last} {
  \part{\curpart{} part}
  \foreach \curchap in {\huge First, Second, Third, Last} {
    \chapter{\curchap{} chapter} \lipsum[1]
    \foreach \cursec in {\LARGE First, Second, Third, Last} {
      \section{\cursec{} section}\lipsum[2]
      \foreach \cursubsec in {First, Second, Third, Last} {
        \subsection{\cursubsec{} subsection}\lipsum[3]
        \foreach \cursubsubsec in {First, Second, Third, Last} {
          \subsubsection{\cursubsubsec{} subsubsection}\lipsum[4]
        }% \subsubsection
      }% \subsection
    }% \section
  }% \chapter
}% \part

\end{document}

I have added \huge and \LARGE in section headings in dummy document.

\foreach \curchap in {\huge First, Second, Third, Last} {
    \chapter{\curchap{} chapter} \lipsum[1]
    \foreach \cursec in {\LARGE First, Second, Third, Last} {

Doing this also reflects the change in size of that section heading in TOC page.
Before adding \huge and \LARGE inside the section heading

After

I want to make font size of sections and chapter headings in TOC page to be independent of what happens to them inside the document.

Best Answer

You should avoid using font changes within the sectional unit title, as these make their way into the ToC by default. For the odd change in font, I'd suggest using

\section[<ToC entry>]{<document entry>}

where you can specify whatever you want inside <document entry>, but leave <ToC entry> without any font changes. For a more global approach to setting fonts for sectional units, use a package that provides hooks to font settings for <ToC entry> and <document entry>, respectively.

<document entry> font changes is made easy using sectsty or titlesec, while <ToC entry> changes is most typically made using tocloft or titletoc. Specific to sectsty, redefine \Xfont for the sectional unit X. For example,

\renewcommand{\partfont}{\normalfont\Huge\bfseries}

will affect only the <document content> of \part, leaving the <ToC entry> untouched (and without font changes).

For each sectional unit X within the ToC, tocloft provides \cftZfont where X denotes (from the tocloft documentation, section 2.3 Typesetting entries):

  • part for \part titles
  • chap for \chapter titles
  • sec for \section titles
  • subsec for \subsection titles
  • subsubsec for \subsubsection titles
  • para for \paragraph titles
  • subpara for \subparagraph titles
  • fig for figure \caption titles
  • subfig for subfigure \caption titles
  • tab for table \caption titles
  • subtab for subtable \caption titles

Here's an example of how to change the various components associated with different sectional units:

enter image description here

\documentclass{report}

\usepackage{tocloft,lipsum,pgffor,sectsty}

\setcounter{tocdepth}{3}% Include up to \subsubsection in ToC

% Font changes to ToC content of sectional units
\renewcommand{\cftpartfont}{\normalfont\sffamily\bfseries}% \part font in ToC
\renewcommand{\cftchapfont}{\normalfont\large\itshape}    % \chapter font in ToC
\renewcommand{\cftsecfont}{\normalfont\slshape}           % \section font in ToC
\renewcommand{\cftsubsecfont}{\normalfont\itshape}        % \subsection font in ToC
\renewcommand{\cftsubsubsecfont}{\normalfont\small}       % \subsubsection font in ToC

% Font changes to document content of sectional units
\renewcommand{\partfont}{\normalfont\Huge\bfseries}
\renewcommand{\chapterfont}{\normalfont\huge\bfseries}
\renewcommand{\sectionfont}{\normalfont\LARGE\bfseries}

\begin{document}

\tableofcontents% ToC

% Create a dummy document with multiple (5) levels of sectional units
\foreach \curpart in {First, Second, Third, Last} {
  \part{\curpart{} part}
  \foreach \curchap in {First, Second, Third, Last} {
    \chapter{\curchap{} chapter} \lipsum[1]
    \foreach \cursec in {First, Second, Third, Last} {
      \section{\cursec{} section}\lipsum[2]
      \foreach \cursubsec in {First, Second, Third, Last} {
        \subsection{\cursubsec{} subsection}\lipsum[3]
        \foreach \cursubsubsec in {First, Second, Third, Last} {
          \subsubsection{\cursubsubsec{} subsubsection}\lipsum[4]
        }% \subsubsection
      }% \subsection
    }% \section
  }% \chapter
}% \part

\end{document}