# Background image from tikzpicture does not fit the whole page

For a poster, I would like to have an image fill the whole page. This image is supposed to be drawn within a tikz environment as my other content. However, graphicx seems to fail at rescaling when the image aspect ratio is much different fom the paper aspect ratio. My code reads:

\documentclass[]{extarticle}
\usepackage[a0paper,margin=0cm]{geometry}
\usepackage{tikz}
\pagestyle{empty}
\setlength{\parindent}{0pt}

\begin{document}
\begin{tikzpicture}
% draw generic background
\draw[white,line width=0pt] (-.5\textwidth, -.5\textheight) rectangle (.5\textwidth, .5\textheight);
% draw image
\pgftext[center,at={\pgfpoint{0}{0}}]{\includegraphics[width=\textwidth,height=\textheight]{test.jpg}}
\end{tikzpicture}
\end{document}

I use the background to fill the whole page with a tikz environment so that (0,0) is at the center of the page and I can position other tikz objects as needed. As long as I use images which closely fit the page or if I use the command includegraphics[width=\textwidth,height=\textheight,keepaspectratio], the image gets scaled correctly. Otherwise, I get a blank first page and my content is on the second page. In other words, the image does not fit the page size, it is too large! How can I prevent this error from happening? Or is there even a better way to draw the image from within the tikz environment?

-
Add [overlay] tikz option. –  JLDiaz Mar 8 '13 at 15:22
I do not understand, why one should define width and height depending on \textwidth and \textheight with the flag to keep the aspectratio. This might cause problems to my understandings. –  Dominikus K. Mar 8 '13 at 15:28
This is a common approach as for example shown here: How to fit a large figure to a page –  Arnold Meister Mar 8 '13 at 15:59

Here is a simple solution without \pgftext (don't mix pgf and TikZ) and margin=0cm, and using the remember picture and overlay option, the special current page node and \paperwidth x\paperheight:

\documentclass[]{extarticle}
\usepackage[a0paper]{geometry}
\usepackage{tikz}
\pagestyle{empty}
\begin{document}
\begin{tikzpicture}[remember picture,overlay]
% draw image
\node[inner sep=0] at (current page.center)
{\includegraphics[width=\paperwidth,height=\paperheight]{example-image}};
\end{tikzpicture}
\end{document}
-
Thanks, this seems to work for the picture. But I cant figure out how to draw my background now. Also the 'overlay' option might get me into trouble since I am using tikzpictures inside tikzpictures for which the overlay option should be off. –  Arnold Meister Mar 8 '13 at 15:58
Figured out the answer: \draw[white,line width=0pt] (current page.south east) rectangle (current page.north west); works to draw the background. –  Arnold Meister Mar 8 '13 at 16:06
Actually, everything seems to work fine. I only had to change my placing coordinates. Thanks! Overlay is the key here. Just one more question: Why is it bad to mix pgf and tikz? (I also use pgfplots without any problems) –  Arnold Meister Mar 8 '13 at 16:24
@ArnoldMeister A mix between pgf and TikZ is not bad if you know what you do... The PGF directives are not at the same level that the TikZ directives. –  Paul Gaborit Mar 8 '13 at 16:53