# Fancyhead and subsections

I just started to use fancyhead.

I have encountered a problem that my subsection titles are placed on the same row as the header. If the subsection title is too long, the two shunks of text will be printed above each other.

One such example:

I would be happy with any of the two solutions:

1. Remove the subsection title from the headers
2. Make sure the subsectoin title and the header made by me will be on different rows. Some kind of solution with a table perhaps - as in Getting chapter and section in \fancyhead.

I will attach my dummy code below:

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[swedish]{babel}

\usepackage{lipsum}
\usepackage{fancyhdr}
\pagestyle{fancy}

\fancyhead[R]{Studiehandledning \date{\today}}

\title{Studiehandledning till kursen \\
xxxxx}

\begin{document}

\maketitle

\newpage

\section{bla bla}

\lipsum

\subsection{skalleper}

\lipsum

\section{wlä wlä wlä}

\lipsum

\section{olika oolika ffgfd rgrgreg rgdsfgdsfgrd gsdgsdg  gsrgrg}

\lipsum

\subsection{olika oolika ffgfd rgrgreg rgdsfgdsfgrd gsdgsdg  gsrgrg}

\lipsum

\end{document}


One peculiarity is also that only subsections show up in the header, not sections. But that migh be related to the discussion regarding even and odd pages in Getting chapter and section in \fancyhead.

• Not sure what you want, as your points 1 and 2 are a bit contradictory. Do you want or not a subsection title? What about section titles? – Bernard Aug 15 '17 at 16:07
• It is not for the purpose of this report necessary. Therefore two options. The section titles do not appear in the header - as I wrote. Maybe it is due to this odd/even page thing. I'm not sure. – Lars Abrahamsson Aug 15 '17 at 16:14
• But what do you want to have, exactly? – Bernard Aug 15 '17 at 16:30
• It is more about what I do not want to have. I do not want have text intrefering/overlapping my intended header. – Lars Abrahamsson Aug 15 '17 at 16:31

## 1 Answer

Maybe this code does what you want (only your header, and the page number):

\pagestyle{fancy}
\fancyhf{}
\fancyhead[R]{Studiehandledning \date{\today}}
\fancyfoot[C]{\thepage}


Added:

I propose this, using the optional argument of (sub)section when the title is too long, if it makes sense. I think it's simpler to do it with titleps:

\documentclass[a4paper, twoside, swedish]{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{geometry}
\usepackage{babel}

\usepackage{lipsum}

\usepackage{titleps}
\newpagestyle{mine}{%
\large
\headrule
\sethead[\itshape\thesection.\enspace\MakeUppercase{\sectiontitle}][][\itshape Studiehandledning \date{\today}]%
{\itshape Studiehandledning \date{\today}}{}{\itshape\thesubsection\enspace\subsectiontitle}
\setfoot{}{\thepage}{}
}%

\title{Studiehandledning till kursen \\
xxxxx}
\pagestyle{mine}
\begin{document}

\maketitle

\newpage

\section{bla bla}

\lipsum

\subsection{skalleper}

\lipsum

\section{wlä wlä wlä}

\lipsum

\section[olika oolika grrrumph]{olika ffgfd rgrgreg rgdsfgdsfgrd gsdgsdg gsrgrg}

\lipsum

\subsection[olika oolika pfffyiæð]
{olika oolika ffgfd rgrgreg rgdsfgdsfgrd gsdgsdg gsrgrg}

\lipsum

\end{document}


This code works only for two-sided documents, because of the use of the 3 optional arguments of \sethead.

Added 2: For one-sided documents, you can obtain the same result with the \ifoddpage package and this code:

\usepackage{isoddpage}

\sethead{\itshape Studiehandledning \date{\today}}{}%
{\checkoddpage%
\itshape\ifoddpage\thesubsection\enspace\subsectiontitle\else\thesection.\enspace\MakeUppercase{\sectiontitle}\fi}
\setfoot{}{\thepage}{}
}%

• Yes, this indeed is "Solution 1"! Does \fancyhf{} mean that any other headers shouldbe ignored? – Lars Abrahamsson Aug 15 '17 at 16:56
• I presume that "Solution 2" is much trickier? – Lars Abrahamsson Aug 15 '17 at 17:01
• You want subsections titles and your text on the same page? What about section titles? Do they go somewhere, or there should be none? Is it for a twosided or a onesided document? – Bernard Aug 15 '17 at 17:20
• I'd say it's easier with titleps (which comes with titlesec) as one doe not have to struggle with marks. I'll post a code in a moment. Are the lengths of your subsections realistic? You might use the optional argument to have shorter titles. – Bernard Aug 15 '17 at 18:46
• (1): No, it won't. I've posted another code for one sided documents (2) You have to do it byhand, with a code like \section[short title]{A much longer title}. (3) You put everything want in the header (except floats…): images, tables. Usually, you'll have to change the value of \headheight. It might be at the cost of a rape of typographical rules. – Bernard Aug 16 '17 at 15:29