# How to have two lines in fancyhdr

Sometimes I have long chapter and section names. Having them written in a header causes overlapping problems.

So what I would like to have is two lines in my header. I want to have chapter number and name in the upper line, and section number and name, in the second line, both are left aligned.

How can I do that? I am open to any other solutions.

Minimal working example of my problem:

\documentclass[12pt,a4paper]{report}
\usepackage[utf8]{inputenc}

\pagestyle{fancy}

\begin{document}

\chapter{A VERY VERY VERY LONG CHAPTER NAME}
\section{ALSO VERY LONG CHAPTER NAME}
Some text...

\newpage
\section{ANOTHER SECTION}
Some text...

\end{document}


Picture of my problem:

# EDIT

If I were doing this, I would consider two options.

## Option 1

If you are printing double-sided, put the chapter on even pages and the section on odd pages. For example:

\documentclass[12pt,a4paper,twoside]{report}
\usepackage[utf8]{inputenc}
\usepackage[headheight=14pt]{geometry}% don't set these manually but, if you do, you need to ensure that you change the layout dimensions consistently e.g. if headheight is bigger, what else are you going to make smaller to compensate? geometry does this automagically
\usepackage{fancyhdr}
\pagestyle{fancy}
\fancyhf[lh,rh,ch]{}
\fancyhf[leh]{\leftmark}
\fancyhf[roh]{\rightmark}
\begin{document}

\chapter{A VERY VERY VERY LONG CHAPTER NAME}
\section{ALSO VERY LONG CHAPTER NAME}
Some text...

\newpage
\section{ANOTHER SECTION}
Some text...

\newpage

More text.

\end{document}


## Option 2

[Can be combined with Option 1 if desired.]

Use a shorter version of the chapter or section title for the running headers:

\documentclass[12pt,a4paper]{report}
\usepackage[utf8]{inputenc}
\usepackage[headheight=14pt]{geometry}% don't set these manually but, if you do, you need to ensure that you change the layout dimensions consistently e.g. if headheight is bigger, what else are you going to make smaller to compensate? geometry does this automagically
\usepackage{fancyhdr}
\pagestyle{fancy}
\fancyhf[lh,rh,ch]{}
\fancyhf[lh]{\leftmark}
\fancyhf[rh]{\rightmark}
\begin{document}

\chapter[Shortened Long Name]{A VERY VERY VERY LONG CHAPTER NAME}
\section[Abbreviated Name]{ALSO VERY LONG CHAPTER NAME}
Some text...

\newpage
\section{ANOTHER SECTION}
Some text...

\newpage

More text.

\end{document}


# Notes

Whichever approach you choose, you should not specify the content of the section and chapter titles in all caps. They will be in caps in the running headers anyway by default. If you need them in caps for the actual section and chapter titles, then customise the format of these sectional headings appropriately. titlesec is one popular package for doing this.

For example:

\documentclass[12pt,a4paper]{report}
\usepackage[utf8]{inputenc}
\usepackage[headheight=14pt]{geometry}% don't set these manually but, if you do, you need to ensure that you change the layout dimensions consistently e.g. if headheight is bigger, what else are you going to make smaller to compensate? geometry does this automagically
\usepackage{fancyhdr}
\pagestyle{fancy}
\fancyhf[lh,rh,ch]{}
\fancyhf[lh]{\leftmark}
\fancyhf[rh]{\rightmark}
\usepackage[uppercase]{titlesec}
\begin{document}

\chapter[Shortened Long Name]{A Very Very Very Long Chapter Name}
\section[Abbreviated Name]{Also Very Long Chapter Name}
Some text..

\end{document}


produces

Note that I do not recommend this. I think there are far better responses to this problem. However, if you must, you can.

Don't change layout dimensions manually. If you do, you need to make sure everything still adds up to a reasonable layout. If the header height is increased, do you really want all of the additional space to come from the bottom margin? geometry will do something more sensible...

You need a header height of at least 28pt for this - 26pt is insufficient.

\documentclass[12pt,a4paper]{report}
\usepackage[utf8]{inputenc}
\usepackage[headheight=28pt]{geometry}% don't set these manually but, if you do, you need to ensure that you change the layout dimensions consistently e.g. if headheight is bigger, what else are you going to make smaller to compensate? geometry does this automagically
\usepackage{fancyhdr}
\pagestyle{fancy}
\fancyhf[lh,rh,ch]{}
\fancyhf[lh]{\begin{minipage}[b]{\textwidth}\raggedright\leftmark\\\rightmark\\\end{minipage}}
\begin{document}

\chapter{A VERY VERY VERY LONG CHAPTER NAME}
\section{ALSO VERY LONG CHAPTER NAME}
Some text...

\newpage
\section{ANOTHER SECTION}
Some text...

\end{document}


• Hmm, as I am newbie to Latex, I will take your advice. I have edited my question and I am open to other solutions. Thanks for your answer anyways. – massakrienen Oct 29 '15 at 0:30
• @massakrienen Please see edit. – cfr Oct 29 '15 at 0:48
• Thank you for your awesome effort. I will choose option 2. – massakrienen Oct 29 '15 at 1:07
• @massakrienen Great! For single-sided documents (and maybe for reports anyway), I think that's definitely the best option. – cfr Oct 29 '15 at 1:10
• Yes, this is a good option for my case, since I am writing my thesis. Also, I realized that setting the header height to 26pt caused the page numbers not to shown on the paper. I guess this is one of the reasons why you do not recommend what I initially asked for. – massakrienen Oct 29 '15 at 1:26

Much more simple: just add \markboth after the chapter or section:

\documentclass[12pt,a4paper]{report}
\usepackage[utf8]{inputenc}

\pagestyle{fancy}

\begin{document}

\chapter{A VERY VERY VERY LONG CHAPTER NAME}
\markboth{A VERY VERY LONG \\ CHAPTER NAME}{}
\section{ALSO VERY LONG CHAPTER NAME}
Some text...

\newpage
\section{ANOTHER SECTION}
Some text...

\end{document}


I think this was your original idea:

• Welcome to TeX - LaTeX! You need to adjust the page dimensions to accommodate this: your code produces the following message in the log file: Package Fancyhdr Warning: \headheight is too small (26.0pt): Make it at least 27.05003pt. – Andrew Swann Feb 17 '16 at 13:06
• so, instead of \setlength\headheight{26pt} is just to write \setlength\headheight{27.06pt}. The \markboth{}command works perfect. – Andres Diaz Feb 18 '16 at 12:24
• You should update your answer to include this. Usually it would be good to make a corresponding correction to some other vertical dimension in the page layout too. – Andrew Swann Feb 18 '16 at 15:27