2

My problem is quite simple : I want to have a TOC like that :

Chapitre 1 - Some chapter title

Annexe A - Some appendix title

but I get :

Chapitre 1 - Some chapter title

Chapitre A - Some appendix title

In fact I redefined the table of contents (code below)

Same problem with the headers : I want :

Annexe A - Some appendix title

not

Chapitre A - Some appendix title

Here is a MWE to show you the problem :

\documentclass[12pt,a4paper]{book}

% Ecrire en français
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[french]{babel}
\usepackage{lmodern}
\usepackage{xspace} % Pour les espaces automatiques

% En têtes
\usepackage{fancyhdr}
\pagestyle{fancy}
\renewcommand{\sectionmark}[1]{\markright{\thesection~- ~#1}}
\renewcommand{\chaptermark}[1]{\markboth{\chaptername~\thechapter~-~ #1}{}}

\fancypagestyle{main}{
\fancyhead{} % clear all header fields
\fancyhead[LE]{\footnotesize{\scshape\nouppercase{\leftmark}}}
\fancyhead[RO]{\footnotesize{\scshape\nouppercase{\rightmark}}}
\fancyfoot{} % clear all footer fields
\fancyfoot[LE,RO]{\thepage}
\renewcommand{\headrulewidth}{0 pt}
\renewcommand{\footrulewidth}{0 pt}

}


% Part name in TOC
\usepackage{tocloft}
\usepackage{xpatch}
\renewcommand\cftpartpresnum{\hfill}
\renewcommand\cftpartleader{\hfill}
\addtocontents{toc}{\cftpagenumbersoff{part}}
\renewcommand{\thepart}{Partie \Roman{part} --\hspace{-.4cm}}
\renewcommand\cftchappresnum{Chapitre\ }
\renewcommand\cftchapaftersnum{\hfill--\hfill}
\renewcommand\cftchapnumwidth{3.2cm}
\renewcommand\cftdotsep{2}
%\renewcommand{\cftpartleader}{\cftdotfill{\cftdotsep}} %Si on veut mettre des pointillés
%\renewcommand{\cftchapleader}{\cftdotfill{\cftdotsep}} 
\newcommand\Bpart[1]{\part{\texorpdfstring{}{}#1}}
\newcommand\Bchapter[1]{\chapter{\texorpdfstring{}{Chapitre \arabic{chapter} -- }#1}}

% Nouvelles commandes
\newcommand{\clearemptydoublepage}{\newpage{\pagestyle{empty}\cleardoublepage}}


\begin{document}

\tableofcontents

\pagestyle{main}

\chapter{Some plain stuff}

\appendix 

\chapter{Some appendix stuff}

\chapter{Some other}
\end{document} 

A clever thing would be to redefine \chaptername when \appendix came in the code, but I didn't succeed.

If someone knows how to fix this please tell me. Thanks.

  • \@chapapp normally does this it expand to \chaptername or \appendixname – touhami May 18 '16 at 11:17
  • I don't know this command, but I will search – John Marjan May 18 '16 at 11:22
1

Here is a solution

  1. for headers you need to set

\makeatletter
\renewcommand{\chaptermark}[1]{\markboth{\@chapapp~\thechapter~-~ #1}{}}
\makeatother

  1. For toc you need to set

\makeatletter
\renewcommand\cftchappresnum{\@chapapp\ }
\makeatother

and add after \appendix

\makeatletter
\addtocontents{toc}{\protect\renewcommand\protect\cftchappresnum{\@chapapp\ }}
\makeatother

Note you can simply do it with \renewcommand\cftchappresnum{\chaptername\ } and then add after \appendix: \addtocontents{toc}{\protect\renewcommand\protect\cftchappresnum{\appendixname\ }} to avoid using \makeatletter--\makeatother


Complete code

\documentclass[12pt,a4paper]{book}

% Ecrire en français
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[french]{babel}
\usepackage{lmodern}
\usepackage{xspace} % Pour les espaces automatiques

% En têtes
\usepackage{fancyhdr}
\pagestyle{fancy}
\renewcommand{\sectionmark}[1]{\markright{\thesection~- ~#1}}
\makeatletter
\renewcommand{\chaptermark}[1]{\markboth{\@chapapp~\thechapter~-~ #1}{}}
\makeatother

\fancypagestyle{main}{
\fancyhead{} % clear all header fields
\fancyhead[LE]{\footnotesize{\scshape\nouppercase{\leftmark}}}
\fancyhead[RO]{\footnotesize{\scshape\nouppercase{\rightmark}}}
\fancyfoot{} % clear all footer fields
\fancyfoot[LE,RO]{\thepage}
\renewcommand{\headrulewidth}{0 pt}
\renewcommand{\footrulewidth}{0 pt}

}


% Part name in TOC
\usepackage{tocloft}
\usepackage{xpatch}
\renewcommand\cftpartpresnum{\hfill}
\renewcommand\cftpartleader{\hfill}
\addtocontents{toc}{\cftpagenumbersoff{part}}
\renewcommand{\thepart}{Partie \Roman{part} --\hspace{-.4cm}}
\makeatletter
\renewcommand\cftchappresnum{\@chapapp\ }
\makeatother
\renewcommand\cftchapaftersnum{\hfill--\hfill}
\renewcommand\cftchapnumwidth{3.2cm}
\renewcommand\cftdotsep{2}
%\renewcommand{\cftpartleader}{\cftdotfill{\cftdotsep}} %Si on veut mettre des pointillés
%\renewcommand{\cftchapleader}{\cftdotfill{\cftdotsep}} 
\newcommand\Bpart[1]{\part{\texorpdfstring{}{}#1}}
\newcommand\Bchapter[1]{\chapter{\texorpdfstring{}{Chapitre \arabic{chapter} -- }#1}}

% Nouvelles commandes
\newcommand{\clearemptydoublepage}{\newpage{\pagestyle{empty}\cleardoublepage}}


\begin{document}



\tableofcontents

\pagestyle{main}

\chapter{Some plain stuff}

\appendix \makeatletter
\addtocontents{toc}{\protect\renewcommand\protect\cftchappresnum{\@chapapp\ }}
\makeatother

\chapter{Some appendix stuff}

\chapter{Some other}
\end{document}
  • It works perfectly ! – John Marjan May 18 '16 at 16:46

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.