Page backgrounds (eso-pic)

A LaTeX page is assembled as a vertical list and then shipped out in one finished box, which leaves no gap into which a background could be slid underneath. Page backgrounds — a flat tint, a full-bleed photo, a diagonal DRAFT watermark — nevertheless exist, because every package that provides them plays the same single trick: it interrupts the shipout and lays its ink down before the body text. The text is printed afterwards, on top, and the result looks like a background. This page follows that one idea through \pagecolor, eso-pic, the background package and draftwatermark, and ends at the place where most people get burned: the printer and the file size.

\pagecolor versus a real background layer

If a flat, single colour behind the whole page is all you need, the answer is one line — \pagecolor{colour} — and no background package is involved at all. The command comes from color/xcolor rather than the LaTeX kernel, so writing \pagecolor{yellow} without \usepackage{xcolor} gives ! Undefined control sequence. \nopagecolor takes it back off. Two of its properties surprise people. First, it is global and ignores grouping: set it inside an environment or inside braces and the tint still runs from that page to the end of the document (how colours themselves are specified belongs to the colours page). Second, all it can paint is a flat rectangle — no photograph, no logo, no rotated text. Almost everything else on this page exists because of that second limit.

document.tex
\documentclass{article}
\usepackage{xcolor}     % \pagecolor lives here, not in the kernel

\begin{document}
\pagecolor{yellow!10}   % tints this page and every page after it
Text on tinted paper.
\clearpage
\nopagecolor            % back to plain paper
Text on plain paper.
\end{document}

So what actually happens when you want something more complicated than a colour behind the text? By the time LaTeX knows what a page contains, the page is finished: the output routine has assembled one large vertical box and all that remains is to write it out. There is no layer to slide underneath. What the kernel offers instead is a pair of hooks, shipout/background and shipout/foreground, and the mechanism is almost comically direct. shipout/background inserts a zero-sized \hbox as the very first item of the shipout box, so its contents are printed first and the rest of the page simply overprints them. shipout/foreground appends one as the very last item, raised back up to the corner, so it prints last and covers the text. PDF has no z-coordinate — the order in which the ink goes down is the only depth there is. Both hooks open a picture environment whose origin (0,0) sits at the top-left corner of the page with \unitlength at 1 pt, which is why the vertical coordinates you \put into them are normally negative.

The interesting part is that these two hooks are much younger than the packages that use them. They arrived in the LaTeX release of 2020-10-01; before that, every background package patched the output routine on its own, which is why the ecosystem accumulated atbegshi, everyshi and everypage. Those still work, but they are now thin compatibility shims — everypage's \AddEverypageHook{...} is these days literally \AddToHook{shipout/background}{\put(1in,-1in){...}}, where the 1in,-1in shifts the origin one inch in and one inch down from the corner of the sheet, to TeX's traditional reference point. The practical consequence is simple: eso-pic, background and draftwatermark all deposit their material into the same kernel hook. That is why they can be combined — and also why they can end up arguing about who gets printed first.

Artwork on every page with eso-pic and \AddToShipoutPictureBG

eso-pic is the general-purpose tool. \AddToShipoutPictureBG{...} draws its argument behind the text on every page from that point on, and \AddToShipoutPictureFG{...} draws it in front. Rolf Niepraschk's package is older than the kernel hooks and moved onto them in version 3; it survives because it makes no assumption whatsoever about what you want to draw. The starred forms \AddToShipoutPictureBG* and \AddToShipoutPictureFG* apply to the current page only — internally the starred material is emptied again the moment that page is shipped. To stop a background later, call \ClearShipoutPictureBG (or \ClearShipoutPictureFG for the foreground). \AddToShipoutPicture and \AddToShipoutPicture* are old aliases of the BG forms and behave identically.

Inside the hook you are in a picture environment, so you place things with \put(x,y){...}. By default eso-pic moves the origin to the lower-left corner of the sheet (the pscoord option, which is on by default). Load it as \usepackage[texcoord]{eso-pic} and the origin moves to the upper-left instead, with y growing downwards. Counting from a corner every time is miserable, so the package ships helpers: \AtPageLowerLeft, \AtPageUpperLeft and \AtPageCenter relative to the sheet, \AtTextUpperLeft, \AtTextLowerLeft and \AtTextCenter relative to the type area, plus \AtStockLowerLeft and friends when the memoir class is in play. Current LaTeX lets \put take real dimensions, so \put(0,-\paperheight) is legal and the old \LenToUnit wrapper that existed for that purpose is now effectively a pass-through kept only for compatibility. If you are guessing at coordinates, \usepackage[grid]{eso-pic} rules a labelled grid over every page — gridunit=mm by default, with bp, in and pt also available.

document.tex
\documentclass{article}
\usepackage{eso-pic}
\usepackage{graphicx}

% one image stretched over the whole sheet, on every page
\AddToShipoutPictureBG{%
  \AtPageLowerLeft{%
    \includegraphics[width=\paperwidth,height=\paperheight]{background.jpg}}%
}

\begin{document}
The text sits on top of the full-bleed image.
\end{document}

If you want a drawn pattern rather than a photograph, put a tikzpicture inside the hook. \AtPageCenter is the convenient anchor here, because TikZ's own coordinates then radiate from the middle of the sheet and you can reason about everything relative to (0,0). In practice the workflow is: keep the grid option on while you are positioning things, then take it off.

document.tex
\documentclass{article}
\usepackage[grid,gridunit=mm]{eso-pic}  % drop "grid" once the position is right
\usepackage{tikz}

\AddToShipoutPictureBG{%
  \AtPageCenter{%
    \begin{tikzpicture}
      \fill[blue!8] (0,0) circle (6cm);
    \end{tikzpicture}}%
}

\begin{document}
A soft tinted disc sits behind the text on every page.
\end{document}

Restricting a background to one page or to the title page

The answer is: use the starred form, and write it where that page begins. \AddToShipoutPictureBG*{...} applies only to the page being assembled at the moment LaTeX reads the line. So a cover background belongs in the preamble or immediately before \maketitle; anywhere later and it lands on whichever page happened to be open. The same reasoning exposes a trap in \ClearShipoutPictureBG: it is global and takes effect immediately, so calling it in the middle of a page removes the background from that very page, not just from the next one. If the current page should keep its background, send the page out with \clearpage first and clear afterwards. For a background that should cover a run of pages, the standard shape is therefore: start it unstarred, then \clearpage followed by \ClearShipoutPictureBG.

document.tex
\documentclass{article}
\usepackage{eso-pic}
\usepackage{graphicx}

\title{Annual Report}
\author{A. Author}

\begin{document}
% starred form: the cover art lands on this page only
\AddToShipoutPictureBG*{%
  \AtPageLowerLeft{%
    \includegraphics[width=\paperwidth,height=\paperheight]{cover.pdf}}%
}
\maketitle
\clearpage
No background from here on.
\end{document}

The dedicated packages offer the same shortcut in their own idiom. background has firstpage=true for the first page only, and the combination of pages=some with \BgThispage for arbitrary chosen pages. draftwatermark restricts itself to page one with \usepackage[firstpageonly]{draftwatermark}, and can be switched off and back on mid-document with \DraftwatermarkOptions{stamp=false} and {stamp=true}. If all you are laying down is an image, the wallpaper package — a thin layer on top of eso-pic — is convenient: \CenterWallPaper{scale}{file} centres an image, \TileWallPaper{width}{height}{file} tiles it, and \ULCornerWallPaper and friends anchor it to a corner. Better still for this section, every one of those commands has a current-page-only twin whose name carries a This, as in \ThisCenterWallPaper.

The background package: watermarks declared with \backgroundsetup

If you would rather not work out coordinates yourself, Gonzalo Medina's background package is the answer. All configuration is gathered into \backgroundsetup{key=value, ...} and the drawing is done by TikZ. A bare \usepackage{background} already produces the defaults: a large reddish Draft (color=red!45, contents=Draft) crossing the centre of every page at 60 degrees with opacity=0.5. The main keys are contents= (the material — text, an \includegraphics, or a drawing), color= (the whole xcolor range), opacity= (0 is fully transparent, 1 fully opaque), angle= (counterclockwise, −360 to 360), scale=, position= (TikZ node-placement syntax such as current page.center; bare coordinates must not be wrapped in parentheses), placement= (the three presets center, top and bottom), nodeanchor= and anchor=, plus hshift= and vshift= for nudging. \backgroundsetup can be called in the preamble or in the body, as often as you like, so the design can change partway through.

document.tex
\documentclass{article}
\usepackage{background}

\backgroundsetup{
  contents={DRAFT},
  color=red,
  opacity=0.25,
  angle=45,
  scale=8,
  position=current page.center,
}

\begin{document}
Every page carries a diagonal DRAFT watermark. Compile twice.
\end{document}

Three traps. First, always compile twice. The material is a tikzpicture with remember picture, overlay anchored to the current page node, so its absolute position on the sheet depends on what the previous run wrote into the .aux file. On the first run you get LaTeX Warning: Label(s) may have changed. Rerun to get cross-references right. and the watermark is either misplaced or missing. Second, if the contents= material contains LaTeX commands, declare it through \backgroundsetup rather than as a \usepackage option — the option string is parsed in a way that breaks on them. Third, pages=some together with \BgThispage is fine, but the opposite command, \NoBgThispage, must not be used in two-column documents: its implementation relies on afterpage, and afterpage does not cooperate with two-column mode. In two columns, the reliable route is to invert the logic — switch to pages=some and call \BgThispage on the pages that should have the background.

draftwatermark: a DRAFT watermark in one line

If a textual watermark is all you need, Sergio Callegari's draftwatermark is the shortest route. Loading it with \usepackage{draftwatermark} puts a large grey DRAFT at the centre of every page — the defaults are text=DRAFT, angle=45, scale=1, fontsize=0.25\paperwidth, and a colour of colorspec=0.8 in colormodel=gray. Configuration lives in \DraftwatermarkOptions{key=value}: text=, angle=, scale=, fontsize=, color= (which may carry a model, as in {[gray]{0.85}}), hpos=/vpos= (or both at once with pos={x,y}), hanchor=/vanchor= (or letters together, as in anchor=lt), and alignment= for multi-line text. There is exactly one exception. firstpageonly is a package option only; writing \DraftwatermarkOptions{firstpageonly} produces ! Package keyval Error: firstpageonly undefined. To mark just the first page, load the package as \usepackage[firstpageonly]{draftwatermark}.

document.tex
\documentclass{article}
% firstpageonly works only here, as a package option
\usepackage[firstpageonly]{draftwatermark}

\DraftwatermarkOptions{
  text=CONFIDENTIAL,
  color={[gray]{0.85}},
  angle=45,
  fontsize=1.5cm,
}

\begin{document}
Only the first page is marked CONFIDENTIAL.
\end{document}

The very reason this package exists is a small piece of history. Its predecessor draftcopy, by Jürgen Vollmer, drew its watermark with PostScript \specials, which pdfLaTeX cannot interpret; the manual says that this incompatibility with PDF-producing engines was the first motivation for writing draftwatermark. The current package therefore uses no driver-dependent tricks at all and behaves identically under pdfLaTeX, XeLaTeX and LuaLaTeX. The legacy commands \SetWatermarkText{...}, \SetWatermarkScale{...}, \SetWatermarkColor{...}, \SetWatermarkAngle{...} and \SetWatermarkLightness{...} (0 is black, 1 is white) survive for compatibility, but each is just a forwarder to \DraftwatermarkOptions, so new documents should use the key-value form. What is genuinely handy at the end of a project is the stamp family: \usepackage[final]{draftwatermark}nostamp is a synonym — removes the watermark without touching any of the setup, and since final is a common class-wide option, a \documentclass[final]{article} reaches it too. The package's limit is equally clear: draftwatermark only ever adds material to shipout/background, so it cannot stamp over the text. For an overlay, or for strict control of stacking order, use eso-pic's \AddToShipoutPictureFG, KOMA-Script's scrlayer, or the shipout/foreground hook directly. draftwatermark even declares its order inside the hook: it asks to be drawn before eso-pic, so when the two are combined, eso-pic's artwork lands on top of the watermark.

Which background package to use, and what trips people up

In practice, work from the humblest tool upwards: \pagecolor for a colour, draftwatermark for a text watermark, background for a tidy declarative setup, and only when none of those bends to your will, drop down to eso-pic and place things directly with \put. The moment you need something in front of the text, the field narrows to eso-pic (or scrlayer, or the raw hook).

ToolBest forCan it go in front?Watch out for
\pagecolorA flat colour behind everythingNo — it is the paper, not a layerNeeds xcolor; global and ignores grouping
eso-picArbitrary artwork at absolute positionsYes — \AddToShipoutPictureFGYou place it yourself with \put; starred forms are current-page only
backgroundDeclarative diagonal watermarks; easy angle and opacityNo — background onlyTwo runs required; \NoBgThispage fails in two-column mode
draftwatermarkA one-line DRAFT or CONFIDENTIAL markNo — background onlyfirstpageonly is a package option only
wallpaperCentred, tiled or corner-anchored image backgroundsNo — background onlyA thin layer over eso-pic; the \This... variants are current-page only
shipout/backgroundFull control with no package at allYes — use shipout/foregroundOrigin is the top-left corner and y is negative; register with \AddToHook
  • Nothing appears, or it is in the wrong place → compile background twice. With eso-pic, suspect the sign of the y coordinate (the origin is the lower left by default) and stray whitespace outside \put.
  • It should be on the cover but it is on every page → you used the unstarred form. Switch to \AddToShipoutPictureBG* and put it immediately before \maketitle.
  • Clearing it also wiped the page I am on\ClearShipoutPictureBG takes effect immediately; issue a \clearpage first.
  • I need the watermark on top of the text\AddToShipoutPictureFG. Neither draftwatermark nor background can do it; both are background-only.
  • I want the watermark gone from the submitted version\usepackage[final]{draftwatermark} or \DraftwatermarkOptions{stamp=false}; the setup stays, the mark goes.
  • I compile through DVI (dvipdfmx / dvips) → all of these work, but colour, opacity and image inclusion are driver-dependent; eso-pic also has a dvips option.

Printing and file size: what a full-page background really costs

A background that looks beautiful on screen is often a different animal on paper. Start with the physical constraint: office laser and inkjet printers cannot put toner right up to the edge of the sheet. An image stretched to \paperwidth in the belief that it will bleed comes back with a white frame a few millimetres wide on all four sides. If you genuinely need full-bleed printing, the sheet has to be larger than the finished page and then trimmed — that is, the right move is to ask the class or geometry for paper with bleed, not to stretch the image further. The second cost is plainer still: a tint that looks gentle on a backlit screen is a page-wide block of toner on paper. It is slow, it is expensive, and it usually comes out darker than expected. Readability pays too, because every bit of background reduces the contrast against the text, so the safe target for a watermark's opacity is "just noticeable".

File size behaves quite differently depending on what the background is made of. An image pulled in with \includegraphics is embedded in the PDF once and merely referenced by each page, so a hundred-page report with a photographic background is only about as large as the report plus one copy of the photo. A background drawn with TikZ is not like that: the drawing commands are executed again for every page and the shapes land in every page's content stream, so the file grows roughly in proportion to the page count. If an elaborate vector background has pushed your PDF into the megabytes, the fix is easy — compile that drawing once on its own into a standalone PDF and pull it in with \includegraphics. You keep the vector quality, and the embedding happens exactly once.