In order to make a background image that fits the page perfectly, I have tried two things. The first is to use a document class where the dimensions of the page can be set to that of A4, which resulted in the following.
\documentclass[a4paper]{article}
\usepackage{graphicx,tikz}
\usepackage[margin=0cm]{geometry}
\begin{document}
\noindent\resizebox{\pdfpagewidth}{\pdfpageheight}{
\begin{tikzpicture}
\draw (0,0) -- (1,0) -- (1,1) -- (0,1) -- cycle;
\end{tikzpicture}
}
\end{document}
Another thing was to look up the dimensions of A4 in points, to which I found an answer on Wrong A4 measurements? (consistent with the 21x29.7cm), and then make a standalone with those lengths, with the following code.
\documentclass{standalone}
\usepackage{graphicx,tikz}
\begin{document}
\noindent\resizebox{595.276pt}{841.89pt}{
\begin{tikzpicture}
\draw (0,0) -- (1,0) -- (1,1) -- (0,1) -- cycle;
\end{tikzpicture}
}
\end{document}
Here I just drew a rectangle to make sure it covered the page, but unfortunately it didn't, as can be seen in the following image (changed the paper colour to grey to make it visible). Both tex files gave the same output, so there is just one image.
Now I suspected it was the tikz
that made this error, and tried with picture
instead:
\documentclass{standalone}
\usepackage{graphicx,tikz}
\begin{document}
\begin{picture}(595.276,841.89)
\linethickness{10pt}
\multiput(0,0)(595.276,0){2}{\line(0,1){841.89}}
\multiput(0,0)(0,841.89){2}{\line(1,0){595.276}}
\end{picture}
\end{document}
This worked, resulting in the next image (grey just for consistency this time).
The image was used as a background using
\documentclass[a4paper]{article}
\usepackage{graphicx,lipsum} % lipsum for the filling text
\usepackage{wallpaper}
\begin{document}
\CenterWallPaper{1}{img/bg2}
\lipsum[1-5]
\end{document}
Now there is one thing I would like an argumented opinion on, and two questions:
- Would it be better to make a standalone with the A4 dimenions
-possibly not exact- or to use a documentclass that already has the right dimensions (such as
[a4paper]{article}
)? - How does one get
tikz
to fill an image, or to rescale an image to the width and height of the page? The picture environment just isn't enough for most purposes. - When the line
\setlength\unitlength{1pt}
was added just above thepicture
environment, the lines shifted, and the resulting document had extra white at the top and bottom around the image. How could this happen, and how can this be solved?
current page
and has the same size and position as the current page, as long as you use\begin{tikzpicture}[overlay, remember picture]
and compile your document twice. You can access the corners using the standard anchors (current page.north west
for the top left corner, for example).tikzpagenodes
package you would want to consider.