[Tex/LaTex] Chapter title on even header and section title in odd header

fancyhdrheader-footer

I wanted to put the title of the chapter on even header and the title of the section of the chapter to the odd pages.

My headers are now are using this code:

 \begin{document}

\frontmatter % Use roman page numbering style (i, ii, iii, iv...) for the pre-content pages

\setstretch{1.3} % Line spacing of 1.3

% Define the page headers using the FancyHdr package and set up for one-sided printing
\fancyhead{} % Clears all page headers and footers
\rhead{\thepage} % Sets the right side header to show the page number
\lhead{} % Clears the left side page header

\pagestyle{fancy} % Finally, use the "fancy" page style to implement the FancyHdr headers

Moreover, chapters are in separate files and called in a main file.

Best Answer

You can simply use the selectors E and O for even and odd pages. Here is a MWE:

\documentclass{book}
\usepackage{lipsum}
\usepackage{fancyhdr}

\fancyfoot{}
\fancyhead[RO,LE]{\thepage}
\fancyhead[LO]{\leftmark}
\fancyhead[RE]{\rightmark}

\begin{document}

\pagestyle{fancy}

\chapter{Chapter}
\section{section}

\lipsum
\lipsum

\end{document}

Here is the output: enter image description here

You can modify the way chapter and section are displayed by redefining \chaptermark and \sectionmark.

Related Question