1

I want to modify my table of contents so that all letters in it become capital letters. How can I achieve this without changing anything else about the layout? My font does not have small caps, so I cannot simply use

{\scshape \tableofcontents}

Also, I found the following snippet, but it only changes sections:

\usepackage{textcase, etoolbox}
\makeatletter
\patchcmd{\l@section}{#1}{\MakeTextUppercase{#1}}{}{}
\makeatother
2
  • 1
    {\sc\tableofcontents} almost works for me (except for chapter titles, but maybe those are redefined somehow by my style)
    – Ansa211
    Mar 4, 2020 at 13:40
  • @Ansa211 That would probably have worked if I had a font that had small caps. I'll update my question. Thanks!
    – Speldosa
    Mar 4, 2020 at 13:55

1 Answer 1

3

For an article you can use tocloft and etoolbox for uppercase your sections, subsections and subsubsections. With book environment, you need to substitute section->chapter and cftsecfont->cftchapfont.

\documentclass{article}
\usepackage{tocloft}
\usepackage{etoolbox}

\makeatletter
\patchcmd{\l@section}
    {\cftsecfont #1}
    {\cftsecfont {#1}}
    {}
    {}
\makeatother
\renewcommand\cftsecfont{\bf\MakeUppercase} 

\makeatletter
\patchcmd{\l@subsection}
    {\cftsubsecfont #1}
    {\cftsubsecfont {#1}}
    {}
    {}
\makeatother
\renewcommand\cftsubsecfont{\small\MakeUppercase}  

\makeatletter
\patchcmd{\l@subsubsection}
    {\cftsubsubsecfont #1}
    {\cftsubsubsecfont {#1}}
    {}
    {}
\makeatother
\renewcommand\cftsubsubsecfont{\small\MakeUppercase}  

\begin{document}

\tableofcontents 

\section{First one}
\section{Second one}
\subsection{Subsection}
\subsubsection{Subsubsection}

\end{document}

Example

Also, you can use \section[UPPERCASED TEXT]{Normal text} and the same thing with \subsection[]{} and \subsubsection[]{}.

Hope it works! Have a nice day!

4
  • Thanks! This does work for sections, but subsections and subsubsection are still written as normal. Also, it does change the look of the table of contents in some ways (for example, sections are bolded by default but this removes this).
    – Speldosa
    Mar 4, 2020 at 14:22
  • 1
    I updated the answer. Hope it works as you want! Mar 4, 2020 at 14:29
  • It did! I have accepted it now. Thanks again!
    – Speldosa
    Mar 4, 2020 at 18:31
  • Great! Have a nice day @Speldosa Mar 4, 2020 at 20:24

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.