GeneralChange the font of the title in TOC

LaTeX specific issues not fitting into one of the other forums of this category.
Post Reply
yaami
Posts: 12
Joined: Wed Sep 22, 2010 3:43 pm

Change the font of the title in TOC

Post by yaami »

Hi all,

I'm trying to change the title in the table of contents. Latex is displaying the title in the TOC in bold font. But I want the title to be displayed in normal font.

Example:
TOC Current style:

Introduction
sections
TOC desired style:
INTRODUCTION
sections

I tried using the tocloft package but it does not change anything.

Code: Select all

\usepackage[titles]{tocloft}
\renewcommand{\cfttoctitlefont}{\normalfont\MakeUppercase}
How do I change this. Also is there a way to avoid hyphenation in the TOC, without changing the title :)

Thanks.
Last edited by yaami on Thu Jan 06, 2011 7:33 pm, edited 1 time in total.

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

And: Currently, Packt sells ebooks for $4.99 each if you buy 5 of their over 1000 ebooks. If you choose only a single one, $9.99. How about combining 3 LaTeX books with Python, gnuplot, mathplotlib, Matlab, ChatGPT or other AI books? Epub and PDF. Bundle (3 books, add more for higher discount): https://packt.link/MDH5p

frabjous
Posts: 2064
Joined: Fri Mar 06, 2009 12:20 am

Change the font of the title in TOC

Post by frabjous »

The \cfttoctitlefont command is for typesetting the actual title of the table of contents, i.e., the word "Contents" at the top of the page, and since you have the titles option to the package, this is ignored anyway. The command you probably want to redefine is \cftchapfont for chapter titles in the TOC.

The current version of tocloft doesn't seem to support including commands that take arguments, not even at the end of the definition, and this rules out \MakeUppercase. (I could have sworn this used to work.) So here I redefine the relevant command so it does. I throw in a \nohyphens command from hyphenat.

Code: Select all

\documentclass{book}
\usepackage{hyphenat}
\usepackage[titles]{tocloft}
\renewcommand{\cftchapfont}{\normalfont\MakeUppercase}
\makeatletter
\renewcommand*{\l@chapter}[2]{%
  \ifnum \c@tocdepth >\m@ne
    \addpenalty{-\@highpenalty}%
    \vskip \cftbeforechapskip
    {\leftskip \cftchapindent\relax
     \rightskip \@tocrmarg
     \parfillskip -\rightskip
     \parindent \cftchapindent\relax\@afterindenttrue
     \interlinepenalty\@M
     \leavevmode
     \@tempdima \cftchapnumwidth\relax
     \let\@cftbsnum \cftchappresnum
     \let\@cftasnum \cftchapaftersnum
     \let\@cftasnumb \cftchapaftersnumb
     \advance\leftskip \@tempdima \null\nobreak\hskip -\leftskip
     {\cftchapfont {\nohyphens{#1}}}\nobreak
     \cftchapfillnum{#2}}%
  \fi}
  \makeatother
\begin{document}
\tableofcontents
\clearpage
\addcontentsline{toc}{chapter}{Introduction}
\chapter*{Introduction}
\section{A section}
\chapter{Another Which I'll Make Long, Really Very Wonderfully Long So It Might Get Hyphens}
\section{Another Section}
\end{document}
yaami
Posts: 12
Joined: Wed Sep 22, 2010 3:43 pm

Change the font of the title in TOC

Post by yaami »

Thank you frabjous. That helped me a lot. Now the titles in the TOC are exactly how I wanted them to be.

Now I have 2 questions:
1. The number at the title in the TOC is still in bold.
Example:
INTRODUCTION 23
how do I make it look like
INTRODUCTION 23

2. Will adding the code that you provided change any other setting in the document. I'm using the report class. I'm still learning LaTeX, all I know now is using the packages already available. And I must say I could not make the head or tail of the code you provided. My apologies. So I just wanted to confirm if this has any effect on any other settings in the document.

Thanks a lot.
User avatar
frabjous
Posts: 2064
Joined: Fri Mar 06, 2009 12:20 am

Change the font of the title in TOC

Post by frabjous »

Throw in:

Code: Select all

\renewcommand{\cftchappagefont}{\normalfont}
right before \begin{document}.

The code I gave shouldn't have any effect outside of the table of contents. It's just copied from the tocloft.sty file except with two very small changes.
yaami
Posts: 12
Joined: Wed Sep 22, 2010 3:43 pm

Re: Change the font of the title in TOC

Post by yaami »

Thanks a lot frabjous. That worked.
User avatar
localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

Change the font of the title in TOC

Post by localghost »

Now that the problem is solved, please be so kind and mark the topic (not the last post) accordingly as clearly written in the Board Rules (to be read before posting). Please keep that in mind for the future so that further reminders will not be necessary.


Thorsten
Post Reply