[Tex/LaTex] fancyhdr package not working proprely

fancyhdrheader-footer

I'm trying to numerate pages depending on even and odd and add chapter name the left part of the header and section name to the right.

here's the code,

\usepackage{fancyhdr}
\pagestyle{fancy}
\fancyhf{}
\fancyhead[RE]{\leftmark}
\fancyhead[LO]{\rightmark}
\fancyfoot[RO,LE]{\thepage}

the output gives me only the chapter name in the left no matter if it is an odd or even page umber, and the numbering in the footer is always in the right.

Best Answer

Use the twoside option for your document class: for example, for report:

\documentclass[twoside]{report} 

Otherwise, the distinction between E and O has no effect.

In a comment it has been requested to have the same position for the page number for the first pages of a chapter; this can be achieved redefining the plain style (by default this style is applied to the first page of a chapter). The following example illustrates this:

\documentclass[twoside]{report}
\usepackage{fancyhdr}
\usepackage{lipsum}

\usepackage{fancyhdr}
\pagestyle{fancy}
\fancyhf{}
\fancyhead[RE]{\leftmark}
\fancyhead[LO]{\rightmark}
\fancyfoot[RO,LE]{\thepage}
\fancypagestyle{plain}{
\renewcommand\headrulewidth{0pt}
\fancyhf{}
\fancyfoot[RO,LE]{\thepage}
}

\begin{document}

\chapter{Cap}
\section{Sec}
\lipsum[1-90]

\end{document}
Related Question