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
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
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 usingsectsty
ortitlesec
, while<ToC entry>
changes is most typically made usingtocloft
ortitletoc
. Specific tosectsty
, redefine\Xfont
for the sectional unitX
. For example,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
whereX
denotes (from thetocloft
documentation, section 2.3 Typesetting entries):part
for\part
titleschap
for\chapter
titlessec
for\section
titlessubsec
for\subsection
titlessubsubsec
for\subsubsection
titlespara
for\paragraph
titlessubpara
for\subparagraph
titlesfig
for figure\caption
titlessubfig
for subfigure\caption
titlestab
for table\caption
titlessubtab
for subtable\caption
titlesHere's an example of how to change the various components associated with different sectional units: