GeneralUppercase Chapter Entries in ToC

LaTeX specific issues not fitting into one of the other forums of this category.
Post Reply
AleCes
Posts: 286
Joined: Sat Nov 13, 2010 9:54 pm

Uppercase Chapter Entries in ToC

Post by AleCes »

Hello everybody,

I wonder if it's possible to have uppercase chapter entries in the ToC. What I've come up with ultimately doesn't work. Indeed the below code returns the following error message.
! Argument of \hyper@linkstart has an extra }.
<inserted text>
\par
l.2 ...duzione e storia primordiale}{1}{chapter.1}
Here's the minimal example.

Code: Select all

\documentclass{book}
\usepackage{tocloft}

\renewcommand\cftchapfont{\MakeUppercase}

\begin{document}
  \tableofcontents

  \chapter{Introduction}

  \chapter{Conclusion}
\end{document}
Last edited by AleCes on Sun Feb 09, 2014 4:30 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.

AleCes
Posts: 286
Joined: Sat Nov 13, 2010 9:54 pm

Uppercase Chapter Entries in ToC

Post by AleCes »

Strangely enough, \scshape works but \MakeUppercase doesn't.

Code: Select all

\documentclass{book}
\usepackage{tocloft}
\renewcommand{\cftchapfont}{\scshape}
\begin{document}
\tableofcontents
\chapter{Introduction}
\chapter{Conclusion}
\end{document}
User avatar
cgnieder
Site Moderator
Posts: 2000
Joined: Sat Apr 16, 2011 7:27 pm

Uppercase Chapter Entries in ToC

Post by cgnieder »

The tocloft manual shows where \cftchapfont is used: in \l@chapter. That command now contains the part {\cftchapfont #1} which means that \cftchapfont does not get an argument! However, \MakeUppercase needs an argument which is why your attempt fails.

One possible solution could be to patch \l@chapter such that it contains {\cftchapfont{#1}}. This can be done with the help of the etoolbox package:

Code: Select all

\documentclass{book}
\usepackage{tocloft}
\usepackage{etoolbox}

\makeatletter
\patchcmd{\l@chapter}
  {\cftchapfont #1}%   search pattern
  {\cftchapfont {#1}}% replace by
  {}%                  success
  {}%                  failure
\makeatother

\renewcommand\cftchapfont{\MakeUppercase}

\begin{document}
\tableofcontents

\chapter{Introduction}
\chapter{Conclusion}

\end{document}
Regards
site moderator & package author
AleCes
Posts: 286
Joined: Sat Nov 13, 2010 9:54 pm

Uppercase Chapter Entries in ToC

Post by AleCes »

Thank you very much! See, if you don't mind I've got a similar problem over here: http://www.latex-community.org/forum/vi ... =5&t=24441, would the same workaround apply to that as well?
Post Reply