0

I am trying to format my \chapter and \section titles in the table of contents in order to reach this aspect :

enter image description here

I am trying to use titlecontents in order to do this. Here is my code and the result :

\documentclass[10pt,twoside]{book}
\usepackage{fancyhdr}
\pagestyle{fancy}

\usepackage[T1]{fontenc}
\usepackage{librecaslon}


\usepackage{tikz}
\usetikzlibrary{calc}
\usepackage{titlesec}

\usepackage{titletoc}

\titlecontents{chapter}
              [0em]
              {\fontsize{14}{12} \selectfont \filcenter \addvspace{30pt}}%
              {PARTIE \thecontentslabel \\\rule{\linewidth}{0.5pt}\\}%
              {1em}%
              {}%
\titlecontents{section}
              [0em]
              {\fontsize{14}{12} \selectfont \addvspace{30pt}}%
              {Chapitre \thecontentslabel \hspace{1cm}}%
              {}%
              {\enspace \contentspage}%

\begin{document}

\tableofcontents

\chapter{Introduction}
\section{Conditions d'application}

\end{document}

Does anyone know how to improve this ?

  • How to add space between "Partie 1", the line, and between the line and "Introduction" ?

  • How to have a different format for "Chapitre 1" and "Conditions d'application" ?

  • How to have "Conditions d'application" on two lines ?

  • How to get the page number to the correct position ?

Thank you all for your help !


EDIT : thank you @Bernard for your answer. Using this code, I have split my toc in two columns :

\usepackage{pgffor}

\makeatletter
\newcommand{\twocolumntoc}{%
  \chapter*{\contentsname
    \@mkboth{%
      \MakeUppercase\contentsname}{\MakeUppercase\contentsname}}%
  \@starttoc{toc}%
}
\makeatother

As you can see, \titlecontents for \part is not working well. And it seems that page numbers are not well-positioned in this case (look at \subsubsection level, called "Section 1" and "Section 2"). Here is my code (I have tried using \sloppy, it is much better but not perfect) :

\documentclass[10pt,twoside]{book}
\usepackage{fancyhdr}
\pagestyle{fancy}

\usepackage[T1]{fontenc}
\usepackage{librecaslon}


\usepackage{tikz}
\usetikzlibrary{calc}
\usepackage{titlesec}
\usepackage{titletoc}

\usepackage{supertabular}

\renewcommand{\baselinestretch}{0.7}

% **************************
% **************************
% /part formatting
% **************************
% **************************

\setcounter{secnumdepth}{6}
\setcounter{tocdepth}{6}


% **************************
% Fonction pour faire les deux traits encadrant les pages Livre et Partie.
% **************************

\newcommand\framethispage[1][1cm]{%
    \tikz[overlay,remember picture,line width=0.2pt]
    \draw([xshift=(#1),yshift=(-#1)]current page.north west) -- ([xshift=(#1),yshift=(#1)+2mm]current page.south west);%
    \tikz[overlay,remember picture,line width=0.2pt]
    \draw([xshift=(#1),yshift=(-#1)]current page.north west) -- ([xshift=(-#1)-2mm,yshift=(-#1)]current page.north east);%
}

% **************************
% Introduction générale --> \intropart
% **************************

\usepackage{changepage}
\strictpagecheck

\newcommand{\intropart}[1]{
\pagebreak
\checkoddpage
\ifoddpage
    \thispagestyle{empty} \framethispage[2cm] \vspace{-12cm} \Huge \begin{center}
    \textbf{#1}
    \end{center} \pagebreak
  \addcontentsline{toc}{chapter}{Introduction générale} % table of contents line
  %\markboth{\MakeUppercase{Introduction générale}}{}
  \small

\else
\newpage
\thispagestyle{empty}
\pagebreak
~
\newpage
\cleardoublepage
  \newpage \thispagestyle{empty} \framethispage[2cm] \vspace{-12cm} \Huge \begin{center} \textbf{#1} \end{center} \pagebreak
  \addcontentsline{toc}{part}{Introduction générale} % table of contents line
  %\markboth{\MakeUppercase{Introduction générale}}{}
  \newpage
  \pagebreak
  \small
  ~
\fi
\thispagestyle{empty} \cleardoublepage
}

% **************************
% Introduction --> \introchap
% **************************

\newcommand{\introchapter}[1]{\begin{center}
    \textbf{\fontsize{16}{12} \selectfont #1} \vspace{3cm}
\end{center}
  \addcontentsline{toc}{chapter}{Introduction} % table of contents line

}


% **************************
% Livre 1 --> \part
% **************************

\renewcommand{\thepart}{\arabic{part}}

\makeatletter
\def\@part[#1]#2{%
\thispagestyle{empty}
\framethispage[2cm]
\ifnum \c@secnumdepth >\m@ne
\refstepcounter{part}%
\addcontentsline{toc}{part}{\thepart\hspace{1em}#1}%
\else
\addcontentsline{toc}{part}{#1}%
\fi
{\parindent \z@ 
\interlinepenalty \@M
\normalfont
\ifnum \c@secnumdepth >\m@ne
\vspace{-9.5cm}
\begin{center}
\begin{tikzpicture}[my node/.style={anchor=base,inner sep=0pt}]
\node[my node] (center) {\fontsize{12}{12} \selectfont \frutL \text{Livre} \thepart};
\draw($(center.base)+(-1.9cm,-1ex)$)     -- ($(center.base)+(+1.9cm,-1ex)$);
\end{tikzpicture}
\end{center}
\par\nobreak
\fi
\begin{center}
\fontsize{18}{12} \selectfont \acasR #2
\end{center}
\markboth{}{}\par}
\newpage
\@afterheading}
\makeatother


% **************************
% Titre
% **************************

\renewcommand{\contentsname}{\begin{center}
    TABLE ANALYTIQUE
\end{center}

}

% **************************
% Deux colonnes
% **************************

\usepackage{pgffor}

\makeatletter
\newcommand{\twocolumntoc}{%
  \chapter*{\contentsname
    \@mkboth{%
      \MakeUppercase\contentsname}{\MakeUppercase\contentsname}}%
  \@starttoc{toc}%
}
\makeatother

% **************************
% Mise en forme
% **************************

\titlecontents{part}
              [0em]
              {\Large\bfseries\filcenter \addvspace{15pt}}%
              {\qquad\textsf{\textsc{Livre}\enspace\thecontentslabel}\\[-1ex]\rule{\linewidth}{0.5pt}\smallskip\\\qquad}%
              {1em}%
              {}%
\titlecontents{chapter}
              [0em]
              {\Large\bfseries\filcenter \addvspace{15pt}}%
              {\qquad\textsf{\textsc{Partie}\enspace\thecontentslabel}\\[-1ex]\rule{\linewidth}{0.5pt}\smallskip\\\qquad}%
              {1em}%
              {}%
\titlecontents{section}
              [0em]
              {\Large\bfseries\filcenter \addvspace{15pt}}%
              {\qquad\textsf{\textsc{Titre}\enspace\thecontentslabel}\\[-1ex]\rule{\linewidth}{0.5pt}\smallskip\\\qquad}%
              {1em}%
              {}%
\titlecontents{subsection}
              [0em]
              {\large\bfseries \addvspace{8pt}}%
              {\contentspush{\sffamily \textsc{Chapitre} \thecontentslabel \quad}}%
              {}%
              {\enspace\hfill\sffamily\mdseries\contentspage}%
\titlecontents{subsubsection}
              [0em]
              {\large\bfseries \addvspace{8pt}}%
              {\contentspush{\sffamily \textsc{Section} \thecontentslabel \quad}}%
              {}%
              {\enspace\hfill\sffamily\mdseries\contentspage}%
\titlecontents{subsubsubsection}
              [5pt]
              {\large\bfseries \addvspace{8pt}}%
              {\contentspush{\thecontentslabel \quad}}%
              {}%
              {\enspace\hfill\sffamily\mdseries\contentspage}%
\titlecontents{paragraph}
              [10pt]
              {\large \addvspace{8pt}}%
              {\contentspush{\thecontentslabel\text{.} \quad}}%
              {}%
              {\enspace\hfill\sffamily\mdseries\contentspage}%
\titlecontents{subparagraph}
              [20pt]
              {\large \addvspace{3pt}}%
              {\contentspush{\thecontentslabel\text{°} \quad}}%
              {}%
              {\enspace\hfill\sffamily\mdseries\contentspage}%
\begin{document}
\sloppy

\part{Part level not working}

\chapter{Pretty long title}

\section{Title test}

\section{Title test}

\subsection{Title test}

\subsubsection{Title tesssssssst}

\subsubsubsection{Title test}

\subparagraph{Title test}

\subparagraph{Title test}

\paragraph{Title test}

\subsubsubsection{Title test}

\subsubsection{Title test Title test}

\section{Title test}

\chapter{Title test}
\part{Part again}

\twocolumn
\twocolumntoc

\end{document}

Here is the result (look at "Section 1"):

enter image description here

2
  • 1
    So your chapters are parts, and your sections chapters? This is very confusing, semantically… – Bernard Apr 14 '20 at 11:06
  • I know, I am really sorry about this. But \part is already "Livre"... But of course if someone has an answer with "Partie" as \part and "Chapitre" as \chapter, I will change to "Partie" as \chapter and "Chapitre" as \section myself :) – Guliup Apr 14 '20 at 11:36
1

I propose this, though I'm not sure I understand all of your requirements: what do you mean with ‘different format’? I interpreted it as using a smallcaps sans font for ‘Chapitre 1’, so I had to use a sans font with small caps (TeX-Gyre Heros). As to the title on two lines, it is automatic if the title is too long. I used a longer title than yours to show how it can be done playing with contents margin. The \contentspush command was added to have a hang format.

\documentclass[10pt ,twoside, french]{book}
\usepackage{geometry}
\usepackage{babel}
\usepackage{fancyhdr}
\pagestyle{fancy}

\usepackage[T1]{fontenc}
\usepackage{librecaslon}
\usepackage[scale = 1.02]{tgheros}

\usepackage{tikz}
\usetikzlibrary{calc}
\usepackage{titlesec}

\usepackage{titletoc}
\contentsmargin[1em]{4em}
\titlecontents{chapter}
              [0em]
              {\Large\bfseries\filcenter \addvspace{30pt}}%
              {\qquad\textsf{\textsc{Partie}\enspace\thecontentslabel}\\[-1ex]\rule{\linewidth}{0.5pt}\smallskip\\\qquad}%
              {1em}%
              {}%
\titlecontents{section}
              [0em]
              {\large\bfseries \addvspace{30pt}}%
              {\contentspush{\sffamily \textsc{Chapitre} \thecontentslabel \quad}}%
              {}%
              {\enspace\hfill\sffamily\mdseries\contentspage}%

\begin{document}

\tableofcontents

\chapter{Introduction}

\section{Conditions d'application, menues billevesées et autres fariboles}

\end{document}

enter image description here

Edit:

Here is the code you can use to obtain the \part playout compatible whith your needs and the two-column table of contents:

 \titleformat{\part}[display]{%
 \AddToShipoutPictureBG*{\AtPageLowerLeft{%
\hskip20mm\rule[22mm]{0.5pt}{\dimexpr\paperheight-42mm}}%
\AtPageUpperLeft{\hskip20mm\rule[-20mm]{\dimexpr\paperwidth-42mm}{0.5pt}}}\filcenter}%
 {\fontsize{12}{12}\selectfont{\frutL Livre~\thepart}\\ \rule[2pt]{3.8cm}{0.5pt}}{20pt}{\fontsize{18}{12} \selectfont}

\titlecontents{part}
              [0em]
              {\Large\bfseries\filcenter \addvspace{15pt}}%
              {\qquad\textsf{\textsc{Livre}~thecontentslabel}\\[-1ex]\rule{\linewidth}{0.5pt}\smallskip\\\qquad}%
              {1em}%
              {}%

enter image description here

12
  • Thank you so much ! I have two remaining questions : - how can I have only "chapter 1" and not 1.1 ? And how to make this work with \part title ? Using the same code changing \chapter with \part does not seem to work. By the way, thank you, I didn't know about "fariboles" ;) – Guliup Apr 14 '20 at 14:19
  • @Guliup: I don't have time at the moment, but I'll look at it later, this evening. – Bernard Apr 14 '20 at 14:50
  • Thank you very much! And if I may ask you an extra question, it seems that your code does not work with two-columns tables of contents. I have edited my initial question with some explanations (with ou without \sloppy). – Guliup Apr 14 '20 at 15:30
  • Hello @Bernard, sorry to bother you again. Do you have any idea regarding this not-aligned page number? Thanks again for your help. – Guliup Apr 15 '20 at 11:00
  • @Gulliup: Aligned how, exactly? The 3 is at the level of the second line of the title, but perhaps I misunderstand. – Bernard Apr 15 '20 at 11:30

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.