Document Classestocloft and \cftchapfont

Information and discussion about specific document classes and how to create your own document classes.
Post Reply
Keith Emmert
Posts: 12
Joined: Sat Nov 08, 2008 9:24 pm

tocloft and \cftchapfont

Post by Keith Emmert »

Hey all,

The command

Code: Select all

\renewcommand{\cftchapfont}{\normalfont}
does not seem to work.

I need to have one entry of my table of contents -- at the chapter level -- unbolded. Ideas?

I'm using a class built upon REPORT.

Keith

Recommended reading 2024:

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

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

User avatar
gmedina
Posts: 2313
Joined: Wed Jul 11, 2007 11:45 pm

tocloft and \cftchapfont

Post by gmedina »

Hi Keith,

you could try using

Code: Select all

\addcontentsline{toc}{chapter}{\normalfont Some entry}
1,1,2,3,5,8,13,21,34,55,89,144,233,...
Keith Emmert
Posts: 12
Joined: Sat Nov 08, 2008 9:24 pm

tocloft and \cftchapfont

Post by Keith Emmert »

Cool!

That does work for the entry title...unfortunately the associated page number is still bolded.

And no,

Code: Select all

\renewcommand{\cftchappagefont}{\normalfont}
doesn't work.

It's only one entry, I could edit the TOC file and place appropriate commands...I just don't want to have to tell my thesis students to do it....

Keith
User avatar
Juanjo
Posts: 657
Joined: Sat Jan 27, 2007 12:46 am

tocloft and \cftchapfont

Post by Juanjo »

Try this:

Code: Select all

\documentclass{report}
\usepackage{tocloft}
\begin{document}
\tableofcontents
\chapter{One}
\section{One.One}
Text

\addtocontents{toc}{\string\let\string\cftchapfont\string\mdseries}
\addtocontents{toc}{\string\let\string\cftchappagefont\string\mdseries}
\addcontentsline{toc}{chapter}{Unbolded entry}
\addtocontents{toc}{\string\let\string\cftchapfont\string\bfseries}
\addtocontents{toc}{\string\let\string\cftchappagefont\string\bfseries}

\chapter{Two}
Text
\end{document}
The CTAN lion is an artwork by Duane Bibby. Courtesy of www.ctan.org.
Keith Emmert
Posts: 12
Joined: Sat Nov 08, 2008 9:24 pm

Re: tocloft and \cftchapfont

Post by Keith Emmert »

Hey!

That worked.

Now, can you explain why that works?

Also, why does the docs in TOCLOFT "let me down?"

Keith
phi
Posts: 577
Joined: Tue Oct 21, 2008 8:10 pm

tocloft and \cftchapfont

Post by phi »

The problem is that \addcontentsline writes only a line of the form \contentsline{chapter}{heading}{page} without any formatting information into the TOC file. The formatting is done when the TOC file is read in (i.e., when \tableofcontents is executed). As you cannot control individual entries during this execution, the formatting has to go directly into the TOC file.
Another possibility that doesn't require this direct writing could be a temporary redefenition of \thepage, which is expanded during writing:

Code: Select all

\begingroup
  \renewcommand*\thepage{\textmd{\arabic{page}}}
  \addcontentsline{toc}{chapter}{\textmd{Some entry}}
\endgroup
User avatar
Juanjo
Posts: 657
Joined: Sat Jan 27, 2007 12:46 am

tocloft and \cftchapfont

Post by Juanjo »

phi,
I'm afraid that, in this case, your code doesn't work. The TOC just contains the page number, without any format that the redefinition of \thepage could apply.

Keith
From the answer of gmedina, it follows that, in fact, it is not necessary to temporarily redefine \cftchapfont. So, a simpler approach could be:

Code: Select all

\addtocontents{toc}{\string\let\string\cftchappagefont\string\mdseries}
\addcontentsline{toc}{chapter}{\mdseries Unbolded entry}
\addtocontents{toc}{\string\let\string\cftchappagefont\string\bfseries}
As explained by phi, the \addtocontents commands write in the TOC file the necessary commands to temporarily change the page format. Open the .toc file and have a look. Note that the \string command is required to put in the file exactly the command right after. If you remove \string, such a command is expanded before being written, yielding weird results.
The CTAN lion is an artwork by Duane Bibby. Courtesy of www.ctan.org.
phi
Posts: 577
Joined: Tue Oct 21, 2008 8:10 pm

tocloft and \cftchapfont

Post by phi »

Juanjo wrote:phi,
I'm afraid that, in this case, your code doesn't work. The TOC just contains the page number, without any format that the redefinition of \thepage could apply.
You're right, \protected@write redefines \thepage locally as unexpandable, so that it is expanded during the output routine. So you have to circumvent \addcontentsline and use \addtocontents:

Code: Select all

\addtocontents{toc}{\protect\contentsline{section}{\mdseries Some entry}{\mdseries\thepage}}
Unfortunately, this doesn't work with hyperref. Here is something that works, but is probably still too unportable:

Code: Select all

\begingroup
  \patchcmd\addcontentsline
    {\contentsline{#2}{#3}{\thepage}}%
    {\contentsline{#2}{#3}{\mdseries\thepage}}%
    {\addcontentsline{toc}{section}{\texorpdfstring\mdseries{}Some entry}}%
    {}
\endgroup
Keith Emmert
Posts: 12
Joined: Sat Nov 08, 2008 9:24 pm

Re: tocloft and \cftchapfont

Post by Keith Emmert »

Thanks to everyone for your information!

Keith
Post Reply