使用 tocloft 调整目录标题字体、大小和粗细

使用 tocloft 调整目录标题字体、大小和粗细

我想使用该tocloft软件包对我的目录进行一些调整。此 MWE 基于这个问题的可接受答案

\documentclass [a4paper,11pt,twoside]{book}

\usepackage{fontspec} 
%\usepackage{titlesec}
\defaultfontfeatures{Ligatures=TeX}
\setmainfont{Book Antiqua}  
\setsansfont{Liberation Sans} %!Change to any font that you have on your system

\usepackage[dutch,english]{babel}

\usepackage{tocloft}

\renewcommand{\cftbeforechapskip}{\baselineskip}      % allow spacing after each chapter/section entry
\renewcommand{\contentsname}{Contents}
%\addto\captionsenglish{\def\contentsname{Contents}} %! Needed for babel? https://tex.stackexchange.com/questions/35903/formatting-the-title-of-the-toc
\renewcommand{\cftaftertoctitle}{\hfill}
%\renewcommand{\cfttoctitlefont}{\hfill\Large\bfseries} %!some command to make the heading large, bold and sans
\renewcommand{\cftbeforetoctitleskip}{-0.25in}        % Title is 1in from top
\renewcommand{\cftaftertoctitleskip}{2.0\baselineskip}% 1 double space after title
\renewcommand{\cfttoctitlefont}{\hfill}               % Blank space before title
\renewcommand{\cftaftertoctitle}{\hfill}              % Blank space after title
\renewcommand{\cftchapfont}{}                         % Can make it bold faced here; don't put a space in the {}
\renewcommand{\cftchapleader}{\cftdotfill{\cftchapdotsep}}
\renewcommand{\cftchapdotsep}{\cftdotsep}             % Puts dots after chapter entries
\renewcommand{\cftchappresnum}{Chapter\ }             %
\renewcommand{\cftchapaftersnum}{}                    % Don't put a space in the {}
\renewcommand{\cftsecleader}{\cftdotfill{\cftsecdotsep}}%
\renewcommand{\cftchappagefont}{}                      %
\renewcommand{\cftchapnumwidth}{1in}

\setcounter{tocdepth}{0}

\begin{document}

\frontmatter
\tableofcontents

\mainmatter
\chapter{A really long chapter heading that will wrap around in the table of contents and end up inline with the chapter name}
\section{First section}

\chapter{Another chapter}
\end{document}

文档,我原本以为\renewcommand{\cftaftertoctitle}{\hfill}会将标题设置为粗体和大号。我这里哪里做错了?

另外,我想确保将标题字体和条目字体设置为我的 sans 字体。我还需要做其他事情吗?也许可以\renewcommand{\cfttoctitlefont}{\hfill\Large\bfseries\sffamily}

答案1

原始代码有

\renewcommand{\cftaftertoctitle}{\hfill}
%\renewcommand{\cfttoctitlefont}{\hfill\Large\bfseries} %!some command to make the heading huge and bold
\renewcommand{\cftbeforetoctitleskip}{-0.25in}        % Title is 1in from top
\renewcommand{\cftaftertoctitleskip}{2.0\baselineskip}% 1 double space after title
\renewcommand{\cfttoctitlefont}{\hfill}               % Blank space before title
\renewcommand{\cftaftertoctitle}{\hfill}              % Blank space after title
\renewcommand{\cftchapfont}{} 

因此,标题或章节目录条目的任何字体更改均不会使用。将它们设置为\hfill\Large\bfseries\sffamily等将更改为大号、粗体无衬线条目,前提是字体支持这些设置。

如果需要的话,必须对等等进行类似的修改\cftsecfont

\documentclass [a4paper,11pt,twoside]{book}



\usepackage{fontspec} 
\usepackage{titlesec}
\defaultfontfeatures{Ligatures=TeX}
\setmainfont{Book Antiqua}  
\setsansfont{Liberation Sans} %Change to any font that you have on your system

\usepackage[dutch,english]{babel}


\usepackage{tocloft}

\renewcommand{\cftbeforechapskip}{\baselineskip}      % allow spacing after each chapter/section entry
\renewcommand{\contentsname}{Contents}
\addto\captionsenglish{\def\contentsname{Contents}} %! Needed for babel? https://tex.stackexchange.com/questions/35903/formatting-the-title-of-the-toc
\renewcommand{\cftaftertoctitle}{\hfill}
\renewcommand{\cfttoctitlefont}{\hfill\Large\bfseries\sffamily} %!some command to make the heading huge and bold
\renewcommand{\cftbeforetoctitleskip}{-0.25in}        % Title is 1in from top
\renewcommand{\cftaftertoctitleskip}{2.0\baselineskip}% 1 double space after title
\renewcommand{\cftchapfont}{\large\bfseries\sffamily}                         % Can make it bold faced here; don't put a space in the {}
\renewcommand{\cftchappagefont}{\large\bfseries\sffamily}                         % Can make it bold faced here; don't put a space in the {}
\renewcommand{\cftchapleader}{\cftdotfill{\cftchapdotsep}}
\renewcommand{\cftchapdotsep}{\cftdotsep}             % Puts dots after chapter entries
\renewcommand{\cftchappresnum}{Chapter\ }             %
\renewcommand{\cftchapaftersnum}{}                    % Don't put a space in the {}
\renewcommand{\cftsecleader}{\cftdotfill{\cftsecdotsep}}%
\renewcommand{\cftchappagefont}{}                      %
\renewcommand{\cftchapnumwidth}{1in}

\setcounter{tocdepth}{0}


\begin{document}



\frontmatter
\tableofcontents

\mainmatter
\chapter{A really long chapter heading that will wrap around in the table of contents and end up inline with the chapter name}
\section{First section}

\chapter{Another chapter}
\end{document}

在此处输入图片描述

相关内容