# Make a customized page header

I have the following template to writing my thesis.

\documentclass[12pt,a4paper,twoside]{report}
\usepackage{pdfpages}
\usepackage{geometry}\geometry{top=3cm,bottom=3cm,left=3.7cm,right=2.5cm}
\usepackage{fancyhdr}
\pagestyle{fancy}
\fancyhead[CO,CE]{This is the title of the thesis}

\setcounter{secnumdepth}{4}

\usepackage{titlesec}
\titleformat{\chapter}[display]{\normalfont\Huge\bfseries}{\chaptertitlename \ \thechapter}{15pt}{\Huge}
\titlespacing*{\chapter}{0pt}{-3\baselineskip}{20pt}[3.7cm]

\hyphenpenalty=10000
\tolerance=2500
\raggedbottom

\usepackage{units}
\usepackage{nomentbl}
\usepackage{enumitem,calc}

\title{This is the title of the thesis}


Obviously, it gives all the page header as ''This is the title of the thesis'', which is centered.

1. I want the page headers on odd page numbers to be the current section title and right alignment, which is on the second level, such as 1.1, 1.2,... and those on even page numbers to be the current chapter title and left alignment, which is on the first level, such as 1, 2,...

2. Some titles of the chapter or section are too long to be shown in one line in the header. In this case, I want to show it as a shorter title.

How do I achieve the customized page header by modifying the template? Thank you a lot!

• Please show some research effort. What did you try and why didn't it work? This type of header is quite standard, if you search for "latex header" there are tutorials presenting everything that's needed. The same holds for short names of chapters / sections (see e.g. tex.stackexchange.com/q/26234/143325). – magula Sep 24 '17 at 17:13
• Remove both lines starting with \fancyhead to get the default header entries. – esdd Sep 24 '17 at 18:37
• @esdd The OP never came back. Do you want to write an answer? Or do we have a duplicate around? Or close as off-topic as removing a faulty line is basically a typo. – Johannes_B Nov 12 '17 at 11:47
• @Johannes_B Maybe its a duplicate. But my comment was wrong. \fancyhead[CO,CE]{This is the title of the thesis} must be replaced by \fancyhead[LE]{\leftmark} and \fancyhead[RO]{\rightmark}. – esdd Nov 12 '17 at 15:13
• @esdd Who cares if the comment was wrong? :-) +1 for the answer. – Johannes_B Nov 12 '17 at 15:19

Replace \fancyhead[CO,CE]{This is the title of the thesis} by

\fancyhead[LE]{\leftmark}


Example (without the not related code):

\documentclass[12pt,a4paper,twoside]{report}

\usepackage{fancyhdr}
\pagestyle{fancy}
%\fancyhead[CO,CE]{This is the title of the thesis}% <- removed

\usepackage{lipsum}% only for dummy text
\begin{document}
\chapter{A chapter}
\section{A section}
\lipsum[1-20]
\chapter[Short chapter title]{Long chapter title in the text body}
\section[Short section title]{Another section with a long title}
\lipsum[1-20]
\end{document}


Result:

Note that on chapter pages pagestyle plain is used by default. Therefore the page header is empty on chapter pages.