编辑

编辑

问题:

如何使下面的 MWE 中的章节标题变为粗体?

最小工作示例:

\documentclass{book}
\usepackage[utf8]{inputenc}
\usepackage[titles]{tocloft}

\begin{document}

%: ----------------------- Table of contents ------------------------
\renewcommand{\contentsname}{Table of contents}
\renewcommand{\cftchapfont}{\normalfont}
\renewcommand{\cftchappagefont}{\normalfont}
\renewcommand{\cftdotsep}{1}
\renewcommand{\cftchapleader}{\cftdotfill{\cftsecdotsep}}

% Organisational level that receives a numbers
\setcounter{secnumdepth}{2}

% Print table of contents for level 2
% Levels are: 0 - chapter, 1 - section, 2 - subsection, 3 - subsubsection
\setcounter{tocdepth}{2}

% Print the table of contents
\tableofcontents

% Creates a chapter, section and subsection
\chapter{Chapter 1}
\section{Section 1}
\subsection{Subsection 1}

% Creates a chapter, section and subsection
\chapter{Chapter 2}
\section{Section 2}
\subsection{Subsection 2}

\end{document}

答案1

这会将章节标题、页眉和页码更改为粗体,因为标题为粗体而不包含附属内容的情况并不常见。但是,如果您出于某种原因只想将标题设为粗体,只需将其他 2 行恢复为原始代码即可。注释解释了哪一行更改了哪件事。

\documentclass{book}
\usepackage[utf8]{inputenc}
\usepackage[titles]{tocloft}
\renewcommand{\contentsname}{Table of contents}
\renewcommand{\cftchapfont}{\normalfont\bfseries}% titles in bold
\renewcommand{\cftchappagefont}{\normalfont\bfseries}% page numbers in bold
\renewcommand{\cftdotsep}{1}
\renewcommand{\cftchapleader}{\bfseries\cftdotfill{\cftsecdotsep}}% dot leaders in bold
\begin{document}

  \setcounter{secnumdepth}{2}

  \setcounter{tocdepth}{2}

  \tableofcontents

  \chapter{Chapter 1}
  \section{Section 1}
  \subsection{Subsection 1}

  \chapter{Chapter 2}
  \section{Section 2}
  \subsection{Subsection 2}

\end{document}

目录中的粗体 ch

编辑

正如 Mico 指出的那样,如果这就是全部内容,那么只需删除设置字体的行即可\normalfont恢复默认格式,您只需填充点:

\documentclass{book}
\usepackage[utf8]{inputenc}
\usepackage[titles]{tocloft}
\renewcommand{\contentsname}{Table of contents}
\renewcommand{\cftdotsep}{1}
\renewcommand{\cftchapleader}{\bfseries\cftdotfill{\cftsecdotsep}}% dot leaders in bold
\begin{document}

  \setcounter{secnumdepth}{2}

  \setcounter{tocdepth}{2}

  \tableofcontents

  \chapter{Chapter 1}
  \section{Section 1}
  \subsection{Subsection 1}

  \chapter{Chapter 2}
  \section{Section 2}
  \subsection{Subsection 2}

\end{document}

相关内容