4

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.

ehi
  • 233
  • 2
    see http://tex.stackexchange.com/questions/48873/section-title-and-page-number-overlapping-in-heading-fancyhdr – samcarter_is_at_topanswers.xyz Dec 09 '16 at 11:06
  • 2
    or http://tex.stackexchange.com/questions/43431/how-to-make-force-line-break-in-chapter-title-in-toc-chapter-header-if-p – samcarter_is_at_topanswers.xyz Dec 09 '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 04 '17 at 13:36
  • Both links were useful but did not completely solve my problem – ehi Jun 05 '17 at 07: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 Answers1

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}
Andrew Swann
  • 95,762