0

I am currently writing a book in french which is made of three parts (with \part{}). Using the fancyhdr package, I would like to have the tile of my book on the even pages and the name of the part (and not that of the sections inside it) on the odd pages. How can I achieve that, especially since the book's title ("Éléments de Géométrie") contains accents which are not rendered well by fancyhdr.

Here is a picture of these two problems, the title is not rendered properly (left) and that I would like to print only the name of the part and not that of the section (right).

enter image description here

\usepackage{fancyhdr}
\pagestyle{fancy}
\fancyhf{}
\fancyhead[ER]{\nouppercase\leftmark{Éléments de Géométrie}}
\fancyhead[OL]{\nouppercase\rightmark}
\fancyhead[EL,OR]{\thepage}

For character encoding I use

\usepackage[francais]{babel}
\usepackage[T1]{fontenc}
\usepackage{textcomp}
\usepackage[utf8]{inputenc}

It is important to note that sections name which include accents works fine, for example : enter image description here

  • 1
    It's not a problem with fancyhdr, but with input encoding. Which one do you use? – Bernard Oct 29 '19 at 13:40
  • \leftmark and \rightmark are generally set by \chapter and \section. Best avoid them. But your will need to store the Part and Title somewhere (\partname?). – John Kormylo Oct 29 '19 at 13:44
  • @Bernard I've updated my question with the relevant informations. – Emperor_Udan Oct 29 '19 at 13:49
  • Did you check the real encoding of your editor (which is ??)? – Bernard Oct 29 '19 at 13:51
  • @Bernard I am using GNU Emacs, but I have managed to solve the encoding problem just by changing the order in which the packages are listed in the preamble. – Emperor_Udan Oct 29 '19 at 14:02
  • 1
    Fine! B.t.w., the language option is now french, and it's recommended that it be declared via \documentclass, so as to make sure that all language-dependent packages be informed. – Bernard Oct 29 '19 at 14:07
  • @Bernard Thank you, I have updated my code according to your advice. :-) – Emperor_Udan Oct 29 '19 at 14:10

1 Answers1

2

I have managed to solve both of my problems. I solved the encoding issue by making sure to declare this at the very beginning of my preamble :

\usepackage{babel}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{textcomp}

Then in order to have the name of the parts right I used this piece of code based on this answer here :

%%%%%%%%%%%%%%%%%%
% Set up headers %
%%%%%%%%%%%%%%%%%%

\newcommand*\parttitle{}
\let\origpart\part
\renewcommand*{\part}[2][]{%
\ifx\\#1\\% optional argument not present?
  \origpart{#2}%
  \renewcommand*\parttitle{#2}%
\else
  \origpart[#1]{#2}%
  \renewcommand*\parttitle{#1}%
\fi
}

\usepackage{fancyhdr}
\pagestyle{fancy}
\fancyhf{}
\fancyhead[ER]{\nouppercase{Éléments de Géométrie}}
\fancyhead[OL]{\nouppercase\parttitle}
\fancyhead[EL,OR]{\thepage}

Here is the result :

enter image description here