I would like to have a solid rectangle (with some text inside it) as my heading. I tried the following:
\documentclass{article}
\usepackage{tikz}
\usepackage{fancyhdr}
\fancypagestyle{heading1}{
\fancyhead{}
\renewcommand{\headrulewidth}{0pt}
\begin{tikzpicture}
\draw[fill=darkgray] (0,0)rectangle(\paperwidth,2);
\node[white] at (2, 1) {Some heading text on page 1};
\end{tikzpicture}
}
\begin{document}
\thispagestyle{heading1}
Some text on page 1
\end{document}
But the gray rectangle does not extend to the far left side of the page (although it does go to the far right side), nor does it extend to the top.


\hspace*{\dimexpr -1in-\oddsidemargin}. You can also go with tikzpagenodes, everypage or\AddToHook{shipout/foreground}...– John Kormylo Jul 16 '21 at 21:31