[Tex/LaTex] Image behind text with fancy

fancyhdrgraphics

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}}
\chead{\includegraphics[width=1cm]{img.eps}}

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?

Best Answer

Here's one way:

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

enter image description here

Related Question