I have problems with how header and footers are displayed in my document. I have made a minimal example where the problems still exist:

*Problem 1*: Header ruler moves up and down from front- to mainmatter  

*Problem 2*: footer image moves up and down from front- to mainmatter  

*Problem 3*: I want "Sections" to be displayed ALWAYS in the header also at the
beginning of a chapter. Right now there is an empty line underneath the chapter, followed by the header ruler.

[![enter image description here](https://i.stack.imgur.com/L7Mwn.jpg)](https://i.stack.imgur.com/L7Mwn.jpg)

[![enter image description here](https://i.stack.imgur.com/wwYFr.jpg)](https://i.stack.imgur.com/wwYFr.jpg)

This my "code":

```
\documentclass[
   final,
   12pt,
   a4paper,
   oneside
]{book}

\usepackage{tocloft}% to alighn the TOC numbers on the right
\usepackage{setspace}
\usepackage{epstopdf}
\usepackage{lipsum}
\usepackage{textcomp}
\usepackage{listings}

\usepackage{fancyhdr}
    \pagestyle{fancy}
    \pagestyle{fancyplain}
    \fancyhead{}
    \fancyfoot{}
    \fancyfoot[L]{\rule{2cm}{1cm}}
    \fancyfoot[RO, LE] {\thepage}
    \renewcommand{\headrule}{{%
        \hrule height 1.9pt width\headwidth
        \vspace{1.6pt}%
        \hrule height 0.9pt width\headwidth
}}

\lfoot[LE,LO]{\rule{2cm}{1cm}}

\usepackage[
   bottom,      % Footnotes appear always on bottom. This is necessary
                % especially when floats are used
   stable,      % Make footnotes stable in section titles
   %perpage,     % Reset on each page
   %para,       % Place footnotes side by side of in one paragraph.
   %side,       % Place footnotes in the margin
   ragged,      % Use RaggedRight
   %norule,     % suppress rule above footnotes
   multiple,    % rearrange multiple footnotes intelligent in the text.
   %symbol,     % use symbols instead of numbers
]{footmisc}

\begin{document}
\renewcommand{\cftchapaftersnum}{.}

\frontmatter
\pagenumbering{Roman}
\fancyfoot[RO, LE] {\small\thepage}
\thispagestyle{empty}
\fancyfoot[R] {\thepage}
\setlength{\parindent}{0pt}
\setlength{\parskip}{12pt}

\renewcommand\lstlistingname{Code listing}
\renewcommand\lstlistlistingname{List of Listings}
\rhead{\small{List of Listings}}
\addcontentsline{toc}{chapter}{List of Listings}
\lstlistoflistings

\mainmatter
\pagenumbering{arabic}
\onehalfspacing
\fancyhead{}
\pagestyle{plain}
\lhead{}
\rhead{\small\nouppercase\leftmark\\\small\nouppercase\rightmark}
\fancyfoot[R] {\thepage}
\setlength{\parindent}{0pt}
\setlength{\parskip}{12pt}

\chapter{Some Chapter}
\lipsum

\section{Some section}
\lipsum

\end{document}

```

2nd attempt
===========

Now that header and footer are no longer moving around I start feeling happy.

Still there are the other issues I have pointed out.

1. Now List of listings appears twice in the header (once as chapter and below as section)
2. The first section still is not printed in the header (only the chapter is printed and an empty line)

This is what it looks like:

Here is the current code:

```
\documentclass[
   final,
   12pt,
   a4paper,
   oneside
]{book}

\usepackage{tocloft}% to alighn the TOC numbers on the right
\usepackage{setspace}
\usepackage{epstopdf}
\usepackage{textcomp}
\usepackage{listings}

%%# IN NEW BEGIN
\usepackage{lipsum}
\usepackage[headheight=30pt,
            a4paper,
            left=42mm,
            right=29mm,
            top=32mm,
            bottom=38mm
]{geometry}  % or %\setlength{\headheight}{30pt}
%% IN NEW END

\usepackage{fancyhdr}
    %\pagestyle{fancy}
    %\pagestyle{fancyplain}
    %\fancyhead{}
    %\fancyfoot{}
    \fancyhead[L]{}
    \fancyhead[R]{\small\nouppercase\leftmark\\\small\nouppercase\rightmark}
    \fancyfoot[L]{\rule{2cm}{1cm}}
    \fancyfoot[R]{\thepage}
    \fancyfoot[C]{}
    \fancypagestyle{plain}{%
        \fancyhf{} % clear all header and footer fields
        \fancyhead[R]{\small\nouppercase\leftmark\\\small\nouppercase\rightmark}
        \fancyfoot[L]{\rule{2cm}{1cm}}
        \fancyfoot[R]{\thepage}
        \fancyfoot[C]{}
        \renewcommand{\headrule}{{%
        \hrule height 1.9pt width\headwidth
        \vspace{1.6pt}%
        \hrule height 0.9pt width\headwidth
    }}}
    \renewcommand{\headrule}{{%
        \hrule height 1.9pt width\headwidth
        \vspace{1.6pt}%
        \hrule height 0.9pt width\headwidth
    }}

\begin{document}
\renewcommand{\cftchapaftersnum}{.}

%%# IN NEW BEGIN
\pagestyle{fancy}
%%# IN NEW END

\frontmatter
\pagenumbering{Roman}

%% OUT NEW BEGIN
%\fancyfoot[RO, LE] {\small\thepage}
%\thispagestyle{empty}
%\fancyfoot[R] {\thepage}
%% OUT NEW END

\setlength{\parindent}{0pt}
\setlength{\parskip}{12pt}

\renewcommand\lstlistingname{Code listing}
\renewcommand\lstlistlistingname{List of Listings}
\rhead{\small{List of Listings}}
\addcontentsline{toc}{chapter}{List of Listings}
\lstlistoflistings

\mainmatter

%% IN NEW BEGIN
\renewcommand{\sectionmark}[1]{\markright{\thesection~#1}}
%% IN NEW END

\pagenumbering{arabic}
\onehalfspacing

%% OUT NEW BEGIN
%\fancyhead{}
%\pagestyle{plain}
%\lhead{}
%\rhead{\small\nouppercase\leftmark\\\small\nouppercase\rightmark}
%\fancyfoot[R] {\thepage}
%% OUT NEW END

\setlength{\parindent}{0pt}
\setlength{\parskip}{12pt}

\chapter{Some Chapter}
Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.

\section{Some section}

Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.
Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.
Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.
Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.
Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.

\end{document}`

```