# Fancyhdr chapter and section titles overlap when titles are long

I want to make a header using \usepackage{fancyhdr} and \pagestyle{fancy}. But when chapter and section names are long they overlap. Is there an option to force line breaks in the header so that they do not overlap? Here a minimal example:

\documentclass{report}

\usepackage{fancyhdr}
\pagestyle{fancy}

\begin{document}

\chapter{A very long chapter title that should be on the top right}
\section{A very long section title that should be on the top left}

\newpage

\end{document}


I saw that this question was discussed here but I hope that this did not really help me.

• – user36296 Dec 9 '16 at 11:06
• – user36296 Dec 9 '16 at 11:07
• Did one of the linked material help? If so, we can mark this question as a duplicate of the other. – Johannes_B Jun 4 '17 at 13:36
• Both links were useful but did not completely solve my problem – ehi Jun 5 '17 at 7:12
• what you will do, when for example you have chapter title long only two words and the first section title two text line long and second one only with one words? can you imagine appearance of your document? the only correct solution is to use short version of your chapter and section names which have only few words (which can be spaced in one line page header) as synonyms for long chapter's and section's titles. this also show your mastering of topic :-) – Zarko Mar 10 '18 at 12:34

Here is an example of setting headings this way, using \parboxes and \RaggedRight/\RaggedLeft from ragged2e:

\documentclass{report}

\usepackage{fancyhdr,ragged2e}