2

This tex file generates a full-width image of a blue square on the second page, after a completely blank page. What causes the extra page and how to prevent it?

\documentclass{article}
\usepackage{graphicx}
\usepackage[margin=0cm]{geometry}
\usepackage{tikzpagenodes}
\setlength{\parindent}{0pt}
\setlength{\parskip}{0pt}

\begin{document}
\begin{tikzpicture}
\node[inner sep=0pt] (blue) at (0,0)
{\includegraphics[width=\paperwidth]{b0.jpg}};
\end{tikzpicture}%
\end{document}

pdfTeX 3.14159265-2.6-1.40.16 (TeX Live 2015/Debian)

pgf 3.0.1a

M.T
  • 135
  • 1
    Is b0.png a blue square? Try replacing b0.jpg with example-image, do you see the same problem? – caverac Feb 11 '18 at 15:34
  • If the image is so high that it can't fit on the page, LaTeX will try and fail to place it on the first page, and then put it on the second page. What are the dimensions of that image? – Torbjørn T. Feb 11 '18 at 15:38
  • @TorbjørnT. image dimensions are 150x200 pixels. Is there some way to force the first attempt? – M.T Feb 11 '18 at 15:41
  • Can't you just resize the image? If it's just a blue rectangle, then that shouldn't be a problem. Make sure the proportions are the same as that of the papersize (A4 or letter). But what is your purpose here? If you want a blue page, there is \pagecolor{blue}. – Torbjørn T. Feb 11 '18 at 15:52
  • @caverac example-image only uses the first page. I would like to cover the page, even if some of the image does not fit in. I guess my issue is with height=\paperheight or greater? If i set that height i get the same problem again – M.T Feb 11 '18 at 15:53
  • @TorbjørnT. The purpose is to cover the page with an image, – M.T Feb 11 '18 at 15:55
  • 1
    Try for example the methods described in https://tex.stackexchange.com/questions/167719/how-to-use-background-image-in-latex – Torbjørn T. Feb 11 '18 at 16:00
  • You can also use eso-pic for that purpose. –  Feb 11 '18 at 16:08
  • @TorbjørnT. Thanks, the methods there solve my problem. instead of the tikzpictureenvironment, using \tikz works. – M.T Feb 11 '18 at 16:15
  • \tikz is a shortform for the tikzpicture environment, so that's not the key difference. The clue is in the remember picture, overlay options, and using the current page node (described in section 17.13.2 in the pgf/TikZ manual). – Torbjørn T. Feb 11 '18 at 17:52

2 Answers2

3

Try

\documentclass{article}
\usepackage{graphicx}
\usepackage[margin=0cm]{geometry}
\usepackage{tikzpagenodes}
\setlength{\parindent}{0pt}
\setlength{\parskip}{0pt}
\usepackage{eso-pic}
\begin{document}
\AddToShipoutPictureBG*{%
 \AtPageLowerLeft{%
 \begin{tikzpicture}
\node[inner sep=0pt] (blue) at (0,0)
{\includegraphics[width=\paperwidth]{example-image-10x16}};
\end{tikzpicture}}}
%
~\clearpage
second page
\end{document}

If you really want only one page, remove \clearpage and the stuff below it.

1

i cant reproduce your problem ... if you like to have this picture on page center, see if this is what you looking for:

\documentclass{article}
\usepackage[demo]{graphicx}
\usepackage[margin=0cm]{geometry}
\usepackage{tikzpagenodes}
\setlength{\parindent}{0pt}
\setlength{\parskip}{0pt}

\begin{document}
\begin{tikzpicture}[remember picture,overlay]
\node[inner sep=0pt] (blue) at (current page.center) {\includegraphics[width=\paperwidth]{b0.jpg}};
\end{tikzpicture}%
\end{document}

you need to compile at least two times.

enter image description here

addendum: full page image:

\documentclass{article}
\usepackage[demo]{graphicx}
\usepackage[margin=0cm]{geometry}
\usepackage{tikzpagenodes}
%\setlength{\parindent}{0pt}
%\setlength{\parskip}{0pt}

\begin{document}
\begin{tikzpicture}[remember picture,overlay]
\node[inner sep=0pt] (blue) at (current page.center) {\includegraphics[width=\paperwidth,height=\paperheight]{b0.jpg}};
\end{tikzpicture}%
\end{document}

enter image description here

Zarko
  • 296,517
  • I believe it is caused by height exceeding a certain value. Please tell me if you still cannot reproduce my issue once you set height=\paperheight – M.T Feb 11 '18 at 19:47
  • do you can't test this yourself? in my test this work fine, however not to forget to compile document at list twice :-) – Zarko Feb 11 '18 at 20:00