0

I want to produce a table of contents using LaTeX like this image at which the table of contents list are all in capital: enter image description here

So I wrote this LaTeX code:

%To make the sections in uppercase
\makeatletter
\patchcmd{\l@section}{#1}{\MakeUppercase{#1}}{}{}% Sections use UPPERCASE in ToC
\makeatother

And this produced a strange error:

enter image description here

I don't understand the meaning of this error and I don't know how to solve it.

Any help ?

Edit: Here is my complete code:

\documentclass{article}
\usepackage{blindtext}
\usepackage[T1]{fontenc}
\usepackage{hyperref}
\usepackage{tocloft,etoolbox}

%To make the sections in uppercase \makeatletter \patchcmd{\l@section}{#1}{\MakeUppercase{#1}}{}{}% Sections use UPPERCASE in ToC \makeatother

\begin{document}

\renewcommand\thesection{\arabic{section}} %\renewcommand\tableofcontents{\MakeUppercase{tableofcontents}}

%To change the name of table of contents \renewcommand\contentsname{\textbf{Table of Contents}} %\MakeUppercase{\tableofcontents} \tableofcontents

\section{Introduction}

This is the first section.

Lorem ipsum dolor sit amet, consectetuer adipiscing
elit. Etiam lobortisfacilisis sem. Nullam nec mi et neque pharetra sollicitudin. Praesent imperdietmi nec ante. Donec ullamcorper, felis non sodales...

\newpage

\section{Second Section}

Lorem ipsum dolor sit amet, consectetuer adipiscing elit.
Etiam lobortis facilisissem. Nullam nec mi et neque pharetra sollicitudin. Praesent imperdiet mi necante...

\end{document}

Nour
  • 347
  • Please make a full but minimal example. From the error I can see that you're using hyperref which is a very important piece of information that you did not mention in your question. This is why we always ask for a full but minimal example, such that we can see which class and minimal preamble you are using. – daleif Sep 27 '21 at 11:03
  • Yes I am using hyperref package in my code, Is that the cause of the error ? – Nour Sep 27 '21 at 11:42
  • Among otherthings. Note that you really should not add formatting to \...name macros. A lot of macros assume that \...name macros are text with no formatting. – daleif Sep 27 '21 at 12:12
  • This might work: https://tex.stackexchange.com/a/156917/3929, but hyperref has changed a bit since then. So I'm not sure if this is a good solution – daleif Sep 27 '21 at 12:13
  • Thanks :) It worked out for me – Nour Sep 27 '21 at 13:19
  • 1
    Why not use one of the answers to your original question (tex.stackexchange.com/questions/616292) posted on 22 September? You did not acknowledge any of the answers so why should any of the responders do anything more for you? --- GOM – Peter Wilson Sep 27 '21 at 17:59

1 Answers1

1

Since you've added hyperref, a minor adjustment is needed:

enter image description here

\documentclass{article}

\usepackage{blindtext} \usepackage{tocloft,etoolbox} \usepackage{hyperref}

%To make the sections in uppercase \makeatletter \patchcmd{\H@old@sect}{\fi #7}{\fi\texorpdfstring{\MakeUppercase{#7}}{#7}}{}{}% Sections use UPPERCASE in ToC \makeatother

\begin{document}

%To change the name of table of contents \renewcommand\contentsname{\textbf{Table of Contents}}

\tableofcontents

\section{Introduction}

This is the first section.

Lorem ipsum dolor sit amet, consectetuer adipiscing
elit. Etiam lobortisfacilisis sem. Nullam nec mi et neque pharetra sollicitudin. Praesent imperdietmi nec ante. Donec ullamcorper, felis non sodales...

\newpage

\section{Second Section}

Lorem ipsum dolor sit amet, consectetuer adipiscing elit.
Etiam lobortis facilisissem. Nullam nec mi et neque pharetra sollicitudin. Praesent imperdiet mi necante...

\end{document}

Werner
  • 603,163