# [Tex/LaTex] How to place a background image on page (using tikz?) that goes behind everything

I want to place an image behind everything on a specific page in my document to liven it up a bit. The first I tried to do was to do was put in a tikz-picture as background, and it worked pretty well, but infortunately the header gets drawn over.

Here is the essential code I have used so far, and its output:

\documentclass[11pt,a4paper,twoside]{scrbook}
\RequirePackage{microtype}
\RequirePackage{pdfpages}

\usepackage{lipsum}
\usepackage{lettrine}
\usepackage{tikz}
\usepackage{multicol}

% Dimensions:
\setlength\topmargin{-58pt}
\setlength\marginparwidth{-20pt}
\setlength\textwidth{\paperwidth - 82pt}
\setlength\textheight{\paperheight - 112pt}
\setlength\oddsidemargin{-30pt}
\setlength\evensidemargin{-30pt}

\usepackage{fancyhdr}
% Footer
\lfoot{}
\rfoot{}
\cfoot{\vspace{-20pt}\textcolor{black}{\rule{\textwidth}{1pt}}}

% Fonts:
\usepackage{mathptmx}   % Serif
\usepackage{DejaVuSans} % Sans-serif
\usepackage[T1]{fontenc}
\usepackage{xstring}

\begin{document}

\noindent
\begin{tikzpicture}[remember picture,overlay]
\node (background) at (0.5\textwidth,-0.5\textheight+15pt) {\includegraphics[height=\paperheight+20pt]{bak}};
\draw [white , fill=white, opacity=0.7](-15pt,-\topmargin+5pt) rectangle (\textwidth+10pt,-\topmargin-\headheight-10pt);
\draw [white , fill=white, opacity=0.7](-15pt,15pt) rectangle (\textwidth+10pt,-\textheight);
\draw [white , fill=white, opacity=0.7](-15pt,-\textheight-22pt) rectangle (\textwidth+10pt,-\textheight-30pt);
\end{tikzpicture}
\pagestyle{fancy}

\begin{multicols}{2}
\lettrine[loversize=0.1]{A}{S} I said, this is a test. \lipsum
\end{multicols}
\clearpage

\begin{multicols}{2}
\lipsum
\end{multicols}

\end{document}


Notice that of the two pages, only the second has a header. In the other the tikz-picture has drawn on top of it. If there is some way to make tikz draw underneath the header, or even to force a re-draw of the header, that would solve my problems. But I do not know how to do any of these.

Notice also that the footer does show up, whereas the header disappears behind the tikz drawing, for some reason. I don't know what to make of this.

Any ideas?

Here is a suggestion that needs an uptodate KOMA-Script: version 3.16 or newer. Then you can use scrlayer-scrpage instead fancyhdr and define a new pagestyles for the pages with a background image.

\documentclass[11pt,a4paper,twoside]{scrbook}
\usepackage{microtype}
\usepackage{pdfpages}

\usepackage{lipsum}
\usepackage{lettrine}
\usepackage{tikz}
\usepackage{multicol}

% Dimensions:
\usepackage{geometry}
\geometry{
top=59pt,
bottom=53pt,
footskip=50pt,
%marginparwidth=-20pt,
hmargin=41pt
}

\clearpairofpagestyles

\makeatletter
\newcommand*\@backgroundimage{}
\newcommand*\backgroundimage[1]{%
\ifstr{#1}{}{\gdef\@backgroundimage{}}{%
\gdef\@backgroundimage{\includegraphics[height=\dimexpr\paperheight+20pt\relax]{#1}}%
}}

\colorlet{backgroundcolor}{white}
\newcommand*\coloredbg{%
\tikz\fill[backgroundcolor,opacity=.7](0,0)rectangle({\layerwidth},{\layerheight});}

\DeclareNewLayer[background,textarea,
contents=\coloredbg
]{text.bg}
\DeclareNewLayer[background,foot,align=b,
contents=\coloredbg
]{foot.bg}
contents=\coloredbg
\DeclareNewLayer[background,
area={.5\paperwidth}{.5\paperheight}{0pt}{0pt},
contents={\makebox[0pt]{%
\raisebox{0pt}[.5\height][.5\height]{\@backgroundimage}%
}}
]{image.bg}
\makeatother

\usepackage{mathptmx}
\usepackage{DejaVuSans}
\usepackage[T1]{fontenc}
\usepackage{xstring}

\usepackage{mwe}% for the example images

\begin{document}
\backgroundimage{example-image}%<- set the background image
\thispagestyle{backgroundimage}%<- use the background image only on the current page
\begin{multicols}{2}
\lettrine[loversize=0.1]{A}{S} I said, this is a test. \lipsum
\lipsum
\end{multicols}
\clearpage

\backgroundimage{example-image-A}%<- change the background image
\pagestyle{backgroundimage}%<- change the pagestyle
\begin{multicols}{2}
\lipsum\lipsum
\end{multicols}
\end{document}