# Prevent superposition of titles in header (fancy)

I would like to prevent the issue of having titles superposed in the header of my report.

I am using the following code:

  \usepackage{fancyhdr}
\pagestyle{fancy}


Actually, when the current subsection is too long and the section as well, both titles are superposed in the middle of the header. Is there a way to prevent it? Thank you in advance!

EDIT

Typical example :

  \section{This is a supercalifragilisticexpialidocious title for a section}
\newpage
\subsection{I am also a supercalifragilisticexpialidocious subtitle}


When you check the header of the second page, section and subsection displayed are superposed. I wish I could have at least the entire text of the section and on the left part the start of the subsection with "..." before it becomes superposed.

ie, I wish I could have this kind of header :

  1.1 I am also a ...       1 THIS IS A SUPERCALIFRAGILISTICEXPIDALIDOCIOUS TITLE FOR A SECTION


EDIT 2

As requested, a minimum working example. It concerns the second page header.

\documentclass[11pt,a4paper]{article}
\usepackage[utf8]{inputenc}
\usepackage[francais]{babel}
\usepackage[T1]{fontenc}
\usepackage[left=2cm,right=2cm,top=2cm,bottom=2cm]{geometry}

\usepackage{fancyhdr}
\pagestyle{fancy}

\begin{document}
\section{This is a supercalifragilisticexpialidocious title for a section}
\newpage
\subsection{I am also a supercalifragilisticexpialidocious subtitle}

\end{document}

• Welcome to TeX.SX! Please add a minimal working example (MWE) that illustrates your problem. It will be much easier for us to reproduce your situation and find out what the issue is when we see compilable code, starting with \documentclass{...} and ending with \end{document}. You can have a look on our starter guide to familiarize yourself further with our format. – egreg Jun 27 '13 at 7:36
• @Header12: you don't have to post your exact code, but a minimal working example, that is a document starting with \documentclass, ending with \end{document} which reproduces the problem. Furthermore, you just have to load the relevant packages able to reproduce the problem, not the whole preamble. :) – Claudio Fiandrino Jun 27 '13 at 7:52
• You should include an MWE. I don't know if it is possible to do that automatically, but what you could do is, you could use the following syntax of the \section / \subsection commands: \section[short title for headers]{long title} however, this also affects the TOC – bene Jun 27 '13 at 8:00
• It's necessary at leastu to know the fancyhdr settings you're using and the document class. Note that having both the section and subsection titles in a single header makes it easy to get superpositions, because the space is limited. – egreg Jun 27 '13 at 8:03
• Unfortunately the proposed solution is not working on the MWE I provided. Thank you in advance for any help you would proposed. Regards. – Header12 Jun 27 '13 at 12:02

I suggest you to use this answer and manually decide, case-by-case, what to show on the header. I think it's quite impossible do this automatically. As an example:

\documentclass[11pt,a4paper]{article}
\usepackage[utf8]{inputenc}
\usepackage[francais]{babel}
\usepackage[T1]{fontenc}
\usepackage[left=2cm,right=2cm,top=2cm,bottom=2cm]{geometry}%any chances to remove this?
\usepackage{lipsum}

\usepackage{fancyhdr}
\pagestyle{fancy}

\newcommand{\markedsection}[2]{
\section[#2]{#2%
\sectionmark{#1}}\sectionmark{#1}}

\newcommand{\markedsubsection}[2]{
\subsection[#2]{#2%
\subsectionmark{#1}} \subsectionmark{#1}}

\begin{document}
\tableofcontents
\newpage

\markedsection{This is a supercalifragilisticexpialidocious title\dots}{This is a supercalifragilisticexpialidocious title for a section}
\lipsum

\markedsubsection{I am also a super\dots}{I am also a supercalifragilisticexpialidocious subtitle}
\lipsum[3]
\markedsubsection{Another veeery\dots}{Another very very very very very very long title}
\lipsum

\end{document}


This is a MWE:

\documentclass{scrartcl}

\usepackage{fancyhdr}
\pagestyle{fancy}

\begin{document}
\tableofcontents
\newpage

\section[section toc]{section normal text}

\subsection[subsec toc]{subsec normal text}

lorem ipsum
\newpage
lorem ipsum

\end{document}


it might not be as simple as I thought. Apparently your \usepackage[francais]{babel} gives some problem. I extended your code here:

\documentclass[11pt,a4paper]{article}
\usepackage[utf8]{inputenc}
%\usepackage[francais]{babel}
\usepackage[T1]{fontenc}
\usepackage[left=2cm,right=2cm,top=2cm,bottom=2cm]{geometry}

\usepackage{fancyhdr}
\pagestyle{fancy}

\begin{document}
\section{This is a supercalifragilisticexpialidocious title for a section}
\newpage
\subsection{I am also a supercalifragilisticexpialidocious subtitle%
%\subsectionmark{code1}%
}
\subsectionmark{code}

\newpage
lorem ipsum

\end{document}


you can see, the problem is that at the first page of the subsection, there is still the long header of the subsection. If you know uncomment the line with code1 everything looks like you want it. However, I uncommented the babel command as well, since I got an error message because of that and I don't know yet, how this can be solved.

• Thank you for your answer. However, isn't there a command for treating this kind of issue automatically? Everytime I am using this kind of hand-made solutions, I find out that there is something already existing in latex. – Header12 Jun 27 '13 at 8:20
• The problem is, how shall the compiler decide, where to abbreviate? Therefore, it only gives you a warning and you can then decide, what to do against it. – bene Jun 27 '13 at 8:31