如何用大写字母格式化部分并保留目录文本的正常格式。
我想使用这个命令:
\section{Section Text}
结果类似如下:
\section[Section Text]{\MakeUppercase{Section Text}}
我正在使用以下部分配置:
\def\section{\@startsection{section}{1}{\z@}{\baselineskip}{\baselineskip}{\centering\normalfont\sffamily\bfseries}}%
要获得此类型的结果:
内容
- 章节文本...页码
- ...
1 节正文
文本文本文本。我想使用无衬线字体和大写字母的部分标题。
是否可以?
答案1
虽然你当然可以用其他方式来实现,但我发现最简单的方法是使用 titlesec 包来自定义标题,并使用其配套的 titletoc 包来自定义目录条目;请参阅文档。
\documentclass{article}
\usepackage{titlesec}% package for customizing headings
\usepackage{titletoc}% package for customizing the toc
\titleformat{\section}% the command you want to format
{\bfseries\sffamily\MakeUppercase}% the style/commands applied to entire title
{\thesection}% format of the number label; here just the number
{0.5em}% spacing after the number
{}% additional styles applied to just the title itself
\dottedcontents{section}% level of toc you want to customize
[1em]% spacing on left of number
{}% code before each section entry
{1em}% width of section number in toc
{1pc}% spacing between dots
\titlecontents{section}% level of toc you want to customize
[1em]% spacing to the left where titles start
{}% code applied before entry
{\thecontentslabel. }%formatting of numbered entry labels
{}% format of unnumbered entry labels
{\dotfill\rlap{\makebox[1em][r]{\thecontentspage}}}% formatting after the title
{}% filler
\usepackage{lipsum}% for dummy text
\begin{document}
\tableofcontents
\section{First Section}
\lipsum[1]
\section{Second Section}
\lipsum[2]
\end{document}