错误 - 目录大写

错误 - 目录大写

我想使用 LaTeX 制作一个目录,像这张图片一样,其中目录列表全部以大写字母显示: 在此处输入图片描述

所以我写了这个 LaTeX 代码:

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

这产生了一个奇怪的错误:

在此处输入图片描述

我不明白这个错误的含义,也不知道如何解决它。

有什么帮助吗?

编辑:这是我的完整代码:

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

答案1

由于您已添加hyperref,需要进行微小的调整:

在此处输入图片描述

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

相关内容