4

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 some LaTeX code, but nothing worked right. The commented sections is my trials, and here is my code:

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

\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}

I don't understand what went wrong. How can I fix it?

1
  • Why do you want to make it less readable? Don't you like your Readers Sep 23 at 6:12
3

enter image description here

Must work for You

\documentclass{article}
\usepackage{etoolbox}

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

\begin{document}

\tableofcontents

\newpage
\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}
2

It can be done by patching the macro that writes the section titles to the .toc file. Probably the "Table of contents" and section titles should also be changed to uppercase. (See alternative bellow)

a

\documentclass{article}
\usepackage{blindtext}
\usepackage[T1]{fontenc}
\usepackage{etoolbox} % for the patch

% added <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
\makeatletter
\patchcmd{\@sect}
{\fi#7}
{\fi\small\MakeUppercase{#7}}
{}{}
\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}

Alternative

Have everything in capital letters by changing the default fonts used for sections. (Includes the title of the table of contents)

b

\documentclass{article}
\usepackage{blindtext}
\usepackage[T1]{fontenc}
\usepackage{etoolbox} % for the patch

% added <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
\makeatletter
\patchcmd{\@sect}
{\fi#7}
{\fi\small\MakeUppercase{#7}}
{}{}

\renewcommand\section{\@startsection {section}{1}{\z@}% added <<<<<
    {-3.5ex \@plus -1ex \@minus -.2ex}%
    {2.3ex \@plus.2ex}%
    {\normalfont\Large\bfseries\MakeUppercase}}
\makeatother    

\renewcommand\contentsname{Table of Contents}       

\begin{document}
    
    \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}
0

This answer only sets the section title in the ToC in uppercase; it does not change any of them in the document.

% tocucprob.tex  SE 616292

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

%%% code from SE 531174 by Phelype Oleinik
%%% which makes \UppercaseIt a declrative form of \MakeUppercase
\newcommand\UppercaseIt{%
  \expandafter\UppercaseItAux
    \expandafter{\iffalse}\fi}
\newcommand\UppercaseItAux[1]{%
  \def\uppercasetmpa{\MakeUppercase{#1}}%
  \expandafter\uppercasetmpa\iffalse{\fi}}

% Uppercase the section titles in the ToC
\renewcommand{\cftsecfont}{\UppercaseIt}

\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}

enter image description here

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.