# Header rule doesn't pass over the margins

I am trying to customize the header rule using fancyhdr and tikz packages. I wish the rule could overpass the margins. In order to do so I thought that drawing a line with tikz from (-1,0) to (18,0) would get 1 cm over the margins in each side, but what I got was the line crossing over just the left margin and not the right. Here's a MWE of my code:

\documentclass[12pt,a4paper]{report}

\usepackage{geometry}
\geometry{
left = 2cm,
right = 2cm,
top = 3cm,
bottom = 2cm
}
\usepackage[utf8]{inputenc}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{graphicx}
\usepackage{tikz}
\usepackage{lipsum}

\usepackage{fancyhdr}
\pagestyle{fancy}
\chead{$$\circledast$$}
\raisebox{.3cm}{%
\begin{tikzpicture}[x=1cm,y=1cm]
\draw (-1,0) to (18,0);
\end{tikzpicture}
}
}
\begin{document}
\lipsum[1-20]
\end{document}


Here's an image of what I got (above) and what I'd like to have (below):

• You should have a look at the warnings your document produces. The headheight is too small and the warning will tell you which value is the minimal necessary height. – samcarter_is_at_topanswers.xyz Jan 18 '19 at 0:00

Quick hack: place a negative space in front of the rule.

\documentclass[12pt,a4paper]{report}

\usepackage{geometry}
\geometry{
left = 2cm,
right = 2cm,
top = 3cm,
bottom = 2cm
}
\usepackage[utf8]{inputenc}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{graphicx}
\usepackage{tikz}
\usepackage{lipsum}

\usepackage{fancyhdr}
\pagestyle{fancy}
\chead{$$\circledast$$}
\hspace*{-1cm}%
\raisebox{.3cm}{%
\begin{tikzpicture}[x=1cm,y=1cm]
\draw (-1,0) to (18,0);
\end{tikzpicture}
}
}
\begin{document}
\lipsum[1-20]
\end{document}


Another approach could be to use a tikzpicture with the remember picture, overlay options. This has the advantage that it avoids the overful box warnings.

\documentclass[12pt,a4paper]{report}

\usepackage{geometry}
\geometry{
left = 2cm,
right = 2cm,
top = 3cm,
bottom = 2cm
}
\usepackage[utf8]{inputenc}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{graphicx}
\usepackage{tikz}
\usepackage{lipsum}

\usepackage{fancyhdr}
\pagestyle{fancy}
\chead{$$\circledast$$}
\raisebox{.3cm}{%
\begin{tikzpicture}[x=1cm,y=1cm,remember picture, overlay]
\draw (-1,0) to (18,0);
\end{tikzpicture}
}
}
\begin{document}
\lipsum[1-20]
\end{document}

• It worked, thank you! By the way, what's the difference between \hspace{} and \hspace*{}? And what these remember picture, overlay options do? – Levy Jan 17 '19 at 23:48
• @Levy About \hspace and \hspace* see tex.stackexchange.com/questions/89082/hspace-vs-hspace – samcarter_is_at_topanswers.xyz Jan 17 '19 at 23:57
• @Levy The overlay option makes the tikzpicture behave as if it would not have any width and height. Therefore it does not get pushed to the right by the content that you add on its left site. – samcarter_is_at_topanswers.xyz Jan 17 '19 at 23:59
• @marmot Thanks for your suggestion. In this particular case, I would prefer no not use absolute positioning with respect to the page. By using positioning relative the the headline content, this will adapt in case something in the headline changes, for example the font size or the top margin. – samcarter_is_at_topanswers.xyz Jan 18 '19 at 9:16

You don't need to use a hammersledge like tikz for this: the titleps package, which comes with titlesec, can replace fancyhdr, and it defines a widenhead command:

\documentclass[12pt, a4paper]{report}

\usepackage{geometry}
\geometry{%
hmargin = 2cm,
top = 3cm,
bottom = 2cm
}%
\usepackage[utf8]{inputenc}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{graphicx}
\usepackage{tikz}
\usepackage{lipsum}

\usepackage{titleps}

\newpagestyle{wide}{%
\sethead{\hspace{1cm}Ex Tunc}{$$\circledast$$}{Ex Nunc\hspace{1cm}}
\setfoot{}{\thepage}{}
}%
\pagestyle{wide}

• Thank you for your answer. I didn't know about the titlepspackage. – Levy Jan 22 '19 at 14:43