3

I would like to use the tocloft package to make some adjustments to my TOC. This MWE is based on the accepted answer to this question.

\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}

From the documentation, I would have thought that \renewcommand{\cftaftertoctitle}{\hfill} would have set the title to bold and large. What am I getting wrong here?

Also, I would like to make sure that the title font and entry fonts are set to my sans font. Is there something more I have to do for that? Maybe \renewcommand{\cfttoctitlefont}{\hfill\Large\bfseries\sffamily}?

  • Are you sure that the Book Antiqua font has a bold version? The font is clearly not a sans - serif font. – user31729 Jan 1 at 8:26
  • @ChristianHupfer I'm quite new to LaTeX, but this font specification is meeting my purposes. The headings are defined by \setsansfont{TeX Gyre Heros} and the body of the text by \setmainfont{Book Antiqua}. The bold in the body come out as bold Book Aniqua. I suspect that I need to do more reading on this? – Simon Jan 1 at 8:34
  • Well, there is a second \renewcommand{\cfttoctitlefont}{\hfill} (right in the middle of the bunch of \cft.... redefinitions) after your first redefinition, so you're wiping out the first setting – user31729 Jan 1 at 8:53
3

The original code has

\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}{} 

So any font change for the title or the chapter toc entries is not used. Setting them to \hfill\Large\bfseries\sffamily etc. will change to large, bold sans serif entries, given that the font supports those settings.

Similar modifications must be applied to \cftsecfont etc, if desired.

\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}

enter image description here

  • I had to switch to Liberation Sans since I don't have TeX Gyre Heros on my computer – user31729 Jan 1 at 9:04
  • 1
    I'll edit the question to use Liberation Sans. Works like a charm. – Simon Jan 1 at 9:05
  • @Simon: You're welcome. Happy TeXing. – user31729 Jan 1 at 9:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.