Consider the following code inspired from egreg's answer to this topic:
\documentclass[11pt,a4paper]{book}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[french]{babel}
\usepackage[top=1in, bottom=1in, left=1in, right=1in, headheight=13.6pt]{geometry}
\usepackage{fancyhdr}
\usepackage{etoolbox}
\usepackage{hyperref}
\usepackage{lipsum}
\pagestyle{fancy}
\fancyhf{}
\renewcommand{\headrulewidth}{1pt}
\renewcommand{\footrulewidth}{0pt}
\fancyhead[LE]{\leftmark}
\fancyhead[RO]{\rightmark}
\begingroup\lccode`~=`:
\lowercase{\endgroup
\newcommand{\partmark}[1]{%
\markboth{\MakeUppercase{\partname\space\thepart~ #1}}{}%
}
\renewcommand{\chaptermark}[1]{%
\markright{\MakeUppercase{\chaptername\space\thechapter~ #1}}%
}
}% end of \lowercase
\makeatletter
\patchcmd{\H@old@part}% would be \@part without hyperref
{\markboth{}{}}
{\partmark{#1}}
{}{}
\makeatother
\begin{document}
\frontmatter
\part*{Préambule}
\tableofcontents
\chapter{Introduction}
\lipsum
\section{Première section}
\lipsum
\lipsum
\lipsum
\section{Deuxième section}
\lipsum
\lipsum
\lipsum
\mainmatter
\part{Premiere partie}
\chapter{Premier chapitre}
\lipsum
\section{Première section}
\lipsum
\lipsum
\lipsum
\section{Deuxième section}
\lipsum
\lipsum
\lipsum
\chapter{Second chapitre}
\lipsum
\section{Première section}
\lipsum
\lipsum
\lipsum
\section{Deuxième section}
\lipsum
\lipsum
\lipsum
\part{Deuxieme partie}
\chapter{Troisieme chapitre}
\lipsum
\section{Première section}
\lipsum
\lipsum
\lipsum
\section{Deuxième section}
\lipsum
\lipsum
\lipsum
\chapter{Quatrieme chapitre}
\lipsum
\section{Première section}
\lipsum
\lipsum
\lipsum
\section{Deuxième section}
\lipsum
\lipsum
\lipsum
\appendix
\part*{Annexes}
\chapter{Premère annexe}
\lipsum
\section{Première section}
\lipsum
\lipsum
\lipsum
\section{Deuxième section}
\lipsum
\lipsum
\lipsum
\chapter{Seconde annexe}
\lipsum
\section{Première section}
\lipsum
\lipsum
\lipsum
\section{Deuxième section}
\lipsum
\lipsum
\lipsum
\end{document}
First this does not work properly, regarding to the headings which is the subject of this question:
- in the front matter, the section title (which should be Préambule) in heading is wrong.
- the formatting of section title is weird (example : "Première PARTIE I: PREMIERE PARTIE")
- in chapters, headings are based on the section and not on the chapter
Actually, I would like to be able to define my own headers "by hand" using a command during the book (this is not shown by the example, but I have a complex structure for a book). Like by redefining a command on each part/chapter:
\renewcommand{\currentpartheader}{Blablabla}
\renewcommand{\currentchapterheader}{BLABLABLA}
knowing that I want the \currentpartheader to be shown on even pages and \currentchapterheader to be shown on odd pages.
How to do that?
Note: I do not need to use fancyhdr if other packages can do the job.
titlesecpackage, and itstitlepssibling, rather thanfancyhdr. – Bernard May 03 '15 at 23:31