[Tex/LaTex] Header line doesn’t span width of page

fancyhdrheader-footermargins

I am using the following code to create a header using fancyhdr:

\documentclass{report}
    \usepackage[margin=3.0cm]{geometry}
    \usepackage{fancyhdr}
    \pagestyle{fancy}

    \renewcommand{\chaptermark}[1]{\markboth{#1}{}}

    \fancyhf{} % clear the headers
    \fancyhead[R]{%
       % We want italics
       \itshape
       % The chapter number only if it's greater than 0
       \ifnum\value{chapter}>0 \chaptername\ \thechapter. \fi
       % The chapter title
       \leftmark}
    \fancyfoot[C]{\thepage}

    \fancypagestyle{plain}{
      \renewcommand{\headrulewidth}{0pt}
      \fancyhf{}
      \fancyfoot[C]{\thepage}
    }

    \setlength{\headheight}{14.5pt}

\begin{document}
test
\end{document}

The problem is the following:
enter image description here
The header line doesn't span the whole width of the page.
I suspect this is because I have \usepackage[margin=3.0cm]{geometry} loaded which adjusts the margins. How can I make sure that the header line still spans the whole page while keeping these margins?

Best Answer

loading geometry befor fancyhdr will fix it

\usepackage[margin=3.0cm]{geometry}
\usepackage{fancyhdr}
\pagestyle{fancy}