7

Trying to use tocloft package to customize a table of contents, but I am running into errors using \MakeUppercase or \uppercase with certain commands, namely \cftsecfont.

When I run the following code I get errors suggesting there are missing or extra }s. Similar errors when I replace \MakeUppercase with \uppercase. If I delete that command entirely it runs with no errors.

\documentclass{article}
\usepackage{tocloft}
\begin{document}
\renewcommand{\cftsecfont}{\bfseries\MakeUppercase}
\tableofcontents
\section{Section One}
\subsection{Subsection}
\section{Section Two}
\end{document}

Similar errors using \cftsubsecfont, etc. What am I doing wrong?

  • 3
    Welcome to TeX.SX! \MakeUppercase is a command with an argument, not a font changing command. – egreg Oct 23 '13 at 23:41
6

You can patch the \l@section (and friends) macros - they are responsible for setting the section/subsection titles in the ToC - to \MakeUppercase the first argument it receives (which includes the number and title):

enter image description here

\documentclass{article}
\usepackage{tocloft,etoolbox}% http://ctan.org/pkg/{tocloft,etoolbox}
\makeatletter
% \patchcmd{<cmd>}{<search>}{<replace>}{<success>}{<failure>}
\patchcmd{\l@section}{#1}{\MakeUppercase{#1}}{}{}% Sections use UPPERCASE in ToC
\patchcmd{\l@subsection}{#1}{\MakeUppercase{#1}}{}{}% Subsections use UPPERCASE in ToC
\makeatother
\begin{document}
\tableofcontents
\section{Section One}
\subsection{Subsection}
\section{Section Two}
\end{document}

The above patch is suggested based on the construction of \l@section (and friends) (from tocloft.dtx):

\renewcommand*{\l@section}[2]{%
  \ifnum \c@tocdepth >\z@
     % <snip>
     {\cftsecfont #1}\nobreak
     \cftsecfillnum{#2}}%
  \fi}

After the patch, \l@section resembles

\renewcommand*{\l@section}[2]{%
  \ifnum \c@tocdepth >\z@
     % <snip>
     {\cftsecfont \MakeUppercase{#1}}\nobreak
     \cftsecfillnum{#2}}%
  \fi}

which forces an UPPERCASE title to be set.

  • Thank you very much for your response. That fixed my uppercase issue, but apparently broke my bibliography. Probably easier for me to just type my section titles in all caps. – Katie R Oct 28 '13 at 15:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.