# How to get \AddToShipoutPicture* to place image at top of page?

I'd have a PDF image that I'd like to use as a background as follows:

• Scaled to width of the page
• Positioned at the top of the page such as it is flush with both upper corners
• The rest of the document should lay out as normal

The image does not cover the entire page. It's more like a banner.

I came up with the following:

\documentclass{article}
\usepackage{eso-pic}
\usepackage{mwe}

\begin{document}
\parbox[t][\paperheight][t]{\paperwidth}{%
\includegraphics[width=\paperwidth]{example-image}
}
}
The quick brown fox jumped over the lazy dogs.
\end{document}


This almost works, except that the image is at the bottom of the page. I also tried wrapped \parbox at with \put(0,0){...} but that didn't help. If I replace \includegraphics with text, the text is rendered at the very bottom left of the page.

How do I get the image to appear flush with the top left corner instead?

Use eso-pic's internal positioning mechanisms. In this case, \AtPageUpperLeft:

\documentclass{article}

\usepackage{eso-pic,graphicx}

\begin{document}

\AtPageUpperLeft{%
\raisebox{-\height}{%
\includegraphics[width=\paperwidth]{example-image}%
}%
}
}
The quick brown fox jumped over the lazy dog.

\end{document}


Since the image would sit on the baseline (in general), \AtPageUpperLeft would actually place the image so it sits "above" the page. However, \raisebox{-\height} brings it down into view on the actual page.

• That just seems rude! "Ok, let's make a frame. Here, good, looks fancy. Now, let's take this image and place it just outside that very frame so nothing of it is actually in the frame." Can you imagine how offended that frame now must be? :P – thymaro Dec 6 at 18:15
• What does \height refer to? – Roxy Dec 7 at 0:28
• @Roxy: \height in \raisebox{<len>}{<stuff>} refers to the height <stuff>. So, -\height will drop <stuff> by its height. So, where formerly the object's bottom was sitting on the baseline, it will not have its top touching the baseline. – Werner Dec 7 at 0:50

\usepackage[pscoord]{eso-pic}


This can go anywhere, preample or anywhere in your document, but before the first usage of the command (as in any programming environment, afaik)

\newcommand\BackgroundPic{%
\put(0,0){%
\parbox[b][\paperheight]{\paperwidth}{%
%           \vfill
\centering
\includegraphics[width=\paperwidth,height=\paperheight,%
keepaspectratio]{../IMG/imagefilename.ext}%
\vfill
}}}


And then in the document or in the titlepage environment, this

\AddToShipoutPicture*{\BackgroundPic}

• if pscoord doesn't solve your case, try textcoord instead, cf. "Package Options" on p. 2 of the eso-pic package documentation (eso-pic v2.0h, dated 2018/04/12). – thymaro Dec 6 at 18:03
• Thanks! That worked, but I'm really confused about the interaction between the \put(0,0), [b] and \vfill at the end. Changing any of these results in the image going to the bottom again. Why is this? Also, I didn't actually need pscoord. – Roxy Dec 6 at 18:03
• Good question. I hope someone strolling by can answer all of this. I'm really just struggling myself, you know. – thymaro Dec 6 at 18:05
• True, since pscoord ist just the default. – thymaro Dec 6 at 18:05
• According to the manual, pscoord uses a coordinate system with the origin (0, 0) in the lower left corner of the page - where you put your parbox. The [b] argument sets the anchor to the bottom of the parbox, while \vfill fills the vertical space on the page not occupied by the image. As \vfill is placed after the image, this moves the image to the top of the page. (The texcoord option for eso-pic would set the origin to the upper left corner of the page.) – epR8GaYuh Dec 6 at 18:21