我想使用 LaTeX 制作一个目录,像这张图片一样,其中目录列表全部以大写字母显示:
所以我写了一些 LaTeX 代码,但都不起作用。注释部分是我的试验,这是我的代码:
\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}
我不明白哪里出了问题。我该如何解决?
答案1
必须为您工作
\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
可以通过修补将章节标题写入.toc
文件的宏来实现。可能还应将“目录”和章节标题更改为大写。(见alternative
下文)
\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}
选择
通过更改各节使用的默认字体,将所有内容都变为大写字母。(包括目录标题)
\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}
答案3
此答案仅将目录中的章节标题设置为大写;它不会更改文档中的任何内容。
% 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}