3

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}

% specifying header
\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
Here, the header looks messy.


\end{document}

enter image description here

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

  • 2
  • 2
  • 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
1

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

Sample output

\documentclass{report}

\usepackage{fancyhdr,ragged2e}
\fancyhead{}
\lhead{\parbox[t]{0.4\textwidth}{\RaggedRight\rightmark\strut}}
\rhead{\parbox[t]{0.4\textwidth}{\RaggedLeft\leftmark\strut}}
\setlength{\headheight}{5\baselineskip}
\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
Some text to demonstrate the header. looks bet.


\end{document}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.