[Tex/LaTex] How to change the style of ToC and \chapter

table of contentstocloft

I would like to adapt the style and content of my ToC, but I'ma little bit stuck with the tocloft package ^^ e.g., how to set the horizontal ruler? Do I change the command that is used in the ToC or do I add this in my latex document? (see page 5 "To add a horizontal line across the whole width of the ToC below an entry for a Part:…")

It should look like this:

CHAPTER N

Title of my chapter


N.M Title of my section ………. pagenumber

N.M Title of my section ………. pagenumber

Variation:

Chapter N | Title of my chapter


N.M Title of my section ………. pagenumber

N.M Title of my section ………. pagenumber

Additionally, I would like to change the font family of the chapters within the ToC and the document itself, as well.

Thank you very much!

Best Answer

Here's one possible solution (feel free to adapt it according to your needs); the tocloft package was used to change the formatting for chapter entries in the ToC and the sectsty package was used to change the formatting for chapter headings in the document:

\documentclass{book}
\usepackage{sectsty}
\usepackage{tocloft}
\usepackage{lipsum}

\newlength\mylen

\renewcommand\cftchappresnum{\chaptername~}
\settowidth\mylen{\bfseries\cftchappresnum\cftchapaftersnum}
\addtolength\cftchapnumwidth{\mylen}

\renewcommand\cftchapaftersnumb{\\\hspace*{\dimexpr-\mylen-1.5em\relax}}
\addtocontents{toc}{\cftpagenumbersoff{chapter}}

\makeatletter
\renewcommand{\@tocrmarg}{0em}
\renewcommand\cftchapafterpnum{%
  \par\vskip-1ex\hspace*{\dimexpr-\mylen-1.5em\relax}\hrulefill\par}
\makeatother

\renewcommand\cftchapfont{\sffamily}
\chapterfont{\sffamily}

\begin{document}
\tableofcontents

\chapter{Test Chapter One}
\section{Test Section One One}
\section{Test Section One Two}
\chapter{Test Chapter Two}
\section{Test Section Two One}
\section{Test Section Two Two}

\end{document}

enter image description here

Related Question