如何\MakeUppercase
在目录中插入章节和小节的内容?
\renewcommand{\l@section}[2]%
{\@dottedtocline{1}{.5em}{1.3em}%
{{\bfseries\selectfont#1}}{#2}}
答案1
这是改变目录中条目外观的一种相当通用的方法。
补丁\xpatchcmd*
只是避免复制定义并修改它的一种方法。中出现的latex.ltx
两个位置被替换为,因此我们可以定义等等,对目录中的标题进行我们想要的操作。#7
\addtocontents
\@nameuse{format#1}{#7}
\formatsection
\documentclass{article}
%%% Patching the kernel \@sect command
\usepackage{regexpatch}
\makeatletter
\xpatchcmd*{\@sect}{\fi#7}{\fi\@nameuse{format#1}{#7}}{}{}
%%% for sections and subsections we want uppercase
\protected\def\formatsection{\MakeUppercase}
\protected\def\formatsubsection{\MakeUppercase}
%%% the other titles are left unchanged
\let\formatsubsubsection\@firstofone
\let\formatparagraph\@firstofone
\let\formatsubparagraph\@firstofone
%%% the following is necessary only if hyperref is used
\AtBeginDocument{%
\pdfstringdefDisableCommands{%
\let\formatsection\@firstofone
\let\formatsubsection\@firstofone
}%
}
\makeatother
\usepackage{hyperref}
\setcounter{secnumdepth}{3}
\begin{document}
\tableofcontents
\section{This is a section}
\subsection{This is a subsection}
\subsubsection{This is a subsubsection}
\end{document}