使用 titletoc 更改目录的颜色和字体

使用 titletoc 更改目录的颜色和字体

我必须创建以下目录: 在此处输入图片描述

现在,我可以创建这个:

在此处输入图片描述

它是使用 titletoc 制作的,即我指定:

\titlecontents{section}[1em]{\normalfont \sffamily \bfseries}
{\thecontentslabel\enspace}
{}
{\titlerule*[1pc]{.}\quad\contentspage}[\vskip 4pt]

这只是我找到并稍作调整的一个例子。不幸的是,我现在无法弄清楚文档,它对我来说似乎太难了。所以如果有人能帮助我维护目录的默认布局并将编号也设为蓝色,我会非常高兴。我所说的默认布局是指删除上面一行代码后得到的布局: 在此处输入图片描述
这正是我需要的,但部分名称采用粗体无衬线字体。以下是整个文件:

\documentclass{article}
\usepackage{amsmath}
\usepackage{titlesec, titletoc}
\usepackage{amssymb}
\usepackage[utf8]{inputenc}
\usepackage{hyperref}

\titleformat{\section}
  {\normalfont \Large \sffamily \bfseries}{\thesection}{1em}{}

\titleformat{\subsection}
  {\normalfont \large \sffamily \bfseries}{\thesubsection}{1em}{}

\titlecontents{section}[1em]{\normalfont \sffamily \bfseries}
{\thecontentslabel\enspace}
{}
{\titlerule*[1pc]{.}\quad\contentspage}[\vskip 4pt]

\hypersetup{
    colorlinks,
    citecolor=black,
    filecolor=black,
    linkcolor=blue,
    urlcolor=black
}
\setcounter{section}{-1}
\title{\vspace{-6em}\textsf{\textbf{{\Huge Template}}}}
\author{}
\date{}

\begin{document}

\maketitle
\tableofcontents
\section{Personal Data}
\section{Introduction}
\subsection{Donald Knuth about civilisation and productivity}
\subsection{What is this about?}
\section{Enumerations \& Tabulars \& Figures \& etc.}
\subsection{image in figure}
\subsection{tabular in table}
\subsection{enumerations}
\section{Mathematical Formulas}
\subsection*{equations}
As upcoming mathematician you should be able to type a formula as simple
as formula (1). The only difficulty should be constraint making use of \texttt{\textbackslash rlap}:
\begin{equation}
 \hspace{10000pt minus 1fil} \int_0^x \frac{1}{t+1}  \text{d}t = \ln (x+1) \qquad \qquad \text{for} \, x \in ] -1, \infty [ \hfilneg 
\end{equation}
\subsection{sets}
Don’t check the formula to be correct, just type it:
\[\forall x, M,N,O: (x \in M \lor (x \in N \land x \in O) \longleftrightarrow (M \cup N) \times (M \cup O) \ni (x,x))\]
\subsection{function definition}
$\varphi: \mathbb{C \times N \rightarrow R}, (z,m) \mapsto (\text{Re}(z+i))^m \cdot m$ is a simple function with $\varphi(2,2) = 8$.
\subsection{linear equations}
\section*{compiler}
This paper is compiled with pdf\LaTeX (August 5, 2021).
\end{document}

相关内容