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


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



    \fancyhf{} % clear the headers
       % We want italics
       % The chapter number only if it's greater than 0
       \ifnum\value{chapter}>0 \chaptername\ \thechapter. \fi
       % The chapter title




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