# Vertical Alignment of footer in fancyhdr package

I have a twosided document in which I use a customized footer with the fancyhdr package. The odd thing is that the inner footer, containing chapter/section info and the outer footer containing page number are vertically non-aligned. The page number is always higher than the text. However, if I use fancyhead instead of fancyfoot, everything is perfectly aligned in the header! No idea why this does not work in the footer the same way.

Can anyone help?

I attach a short script showing the problem. For ease, both header and footer are active to show the difference.

Thanks in advance for your feedback!

Petra

\documentclass[a5paper,twoside,11pt,openany,DIV=calc,ngerman,twocolumn,xcolor=dvipsnames]{scrbook}

\usepackage{lipsum}
\usepackage{fancyhdr}

\pagestyle{fancy}

\newcommand{\lkopf}[2]{\markboth{\ref{#1} #2}{}}
\newcommand{\rkopf}[2]{\markright{\ref{#1} #2}}

\fancypagestyle{plain}{ %
\fancyhf{} % remove everything
\renewcommand{\headrulewidth}{0pt} % remove lines as well
\renewcommand{\footrulewidth}{0pt}
\fancyfoot[LE,RO]{\thepage}
}

\fancypagestyle{myheadings}{
\fancyhf{}
\fancyhead[LE,RO]{\thepage}
\fancyhead[RE]{\leftmark}
\fancyhead[LO]{\rightmark}
\fancyfoot[LE,RO]{\thepage}
\fancyfoot[RE]{\leftmark}
\fancyfoot[LO]{\rightmark}
\renewcommand{\headrulewidth}{0.5pt}
\renewcommand{\footrulewidth}{0.5pt}
}

\pagestyle{myheadings}

\begin{document}

\chapter*{Greetings}
\label{kap:greetings}
\lkopf{kap:greetings}{Greetings}

\twocolumn[
\section*{Greetings A}\label{gruss_A}
]
\rkopf{gruss_A}{Mr. A}
\lipsum
\lipsum
\lipsum
\lipsum

\twocolumn[
\section*{Greetings B}\label{gruss_B}
]
\rkopf{gruss_B}{Mr. B}
\lipsum[0]
\lipsum[100]

\end{document}


## 2 Answers

The issue does not exist if you use package scrlayer-scrpage for header and footer. Note that its usage is suggested for KOMA-Script classes.

\documentclass[
paper=a5,
open=any,
DIV=calc,
ngerman,
twocolumn,
%xcolor=dvipsnames% unused/unknown option
]{scrbook}
\usepackage{lipsum}% only for dummy text
\usepackage{babel}

\usepackage[
manualmark,% set marks manually
headsepline=.5pt,
footsepline=.5pt
]{scrlayer-scrpage}
\clearpairofpagestyles
\ohead{\pagemark}
\ihead{\headmark}
\ofoot*{\pagemark}
\ifoot{\headmark}
\addtokomafont{pageheadfoot}{\normalfont}

\newcommand{\lkopf}[2]{\markboth{\ref{#1} #2}{}}
\newcommand{\rkopf}[2]{\markright{\ref{#1} #2}}

\begin{document}

\addchap*{Greetings}
\label{kap:greetings}
\lkopf{kap:greetings}{Greetings}

\twocolumn[
\addsec*{Greetings A}\label{gruss_A}
]
\rkopf{gruss_A}{Mr. A}
\lipsum
\lipsum
\lipsum
\lipsum

\twocolumn[
\addsec*{Greetings B}\label{gruss_B}
]
\rkopf{gruss_B}{Mr. B}
\lipsum[0]
\lipsum[100]

\end{document}


Note that you are using unnumbered chapters and sections. So the reference to this chapters and sections are empty. Maybe you want to use \nameref?

Example with \nameref in \rkopf:

\usepackage{nameref}
\newcommand{\lkopf}[2]{\markboth{\ref{#1} #2}{}}
\newcommand{\rkopf}[2]{\markright{\nameref{#1} #2}}


Result:

• That did the job. Did not know the scrlayer-scrpage package. Thanks a lot for pointing out! Jul 28, 2018 at 19:21
• @Petra If the answer solves your issue then you can upvote and maybe accept it.
– esdd
Jul 28, 2018 at 22:31

There is a way to overcome this issue but I don’t know why this is happening, maybe someone here can tell us what’s going on. One possible solution is to put the content of the headers and footers inside an \mbox and adjust the \fboxsep to 0pt.

\setlength{\fboxsep}{0pt}
\newcommand{\lkopf}[2]{\markboth{\mbox{\ref{#1} #2}}{}}
\newcommand{\rkopf}[2]{\markright{\mbox{\ref{#1} #2}}}