# Image behind text with fancy

I want to have an image behind the page number in my latex document, and tried to write it like

\fancyhead[CE,CO]{\textcolor{white}{\thepage}}


The problem is: When I first have the line with the page number, and then the image, I only get the image, and if I have the other way round, then I only get the number. How can I have the number in front of the image? Should I use a background image for that?

• What image is it? – Alenanno Feb 5 '16 at 19:01
• A black tent (i.e. totally black figure, vectorized) – arc_lupus Feb 5 '16 at 19:04
• As in a black triangle? – Alenanno Feb 5 '16 at 19:11
• @Alenanno: Yes. – arc_lupus Feb 5 '16 at 20:21

Here's one way:

\documentclass{article}
\usepackage{fancyhdr,stackengine,xcolor,graphicx}
\fancypagestyle{mystyle}{
\includegraphics[width=1cm]{example-image}}}
}
\pagestyle{mystyle}
\begin{document}
My text
\end{document}


• Is there a possibility to shift the image also such that the number is not centered, but slightly shifted in one direction? – arc_lupus Feb 5 '16 at 21:15
• @arc_lupus, one can easily move the page number within the image, by adding the x-shift as the 2nd argument and the y-shift as the 4th argument to \stackinset, as in \stackinset{c}{8pt}{c}{6pt}{inset}{base image}. – Steven B. Segletes Feb 5 '16 at 23:17
• @arc_lupus The 1st argument to \stackinset is the horizontal anchor position, which can be left, center, or right. The 3rd argument is the vertical anchor, either top, center, or bottom. – Steven B. Segletes Feb 5 '16 at 23:19

You can set the content in the sequence that you want them layered.

With the above in mind, we can set the image in the Left header, which will be followed by setting of the Centred header:

\documentclass{article}

\usepackage{graphicx,fancyhdr,xcolor,lipsum}

\pagestyle{fancy}

\begin{document}

\lipsum[1-10]

\end{document}


The Left header is set in a box of width \textwidth which is naturally centred. Adjustment of the positioning of the image may be needed.

If all you want is a white page number on a black background, you can just use

\fancyhead[C]{\raisebox{0pt}[0pt][0pt]{\colorbox{black}{\textcolor{white}{\thepage}}}}


which sets the page number using \colorbox: