79

I am generating one report where I need to use background image. But I found that image always starts leaving some margin space to left side.

\documentclass{article}
\usepackage{wallpaper}
\usepackage{mdframed}
\usepackage[top=2cm, bottom=2cm, outer=0cm, inner=0cm]{geometry}
\begin{document}
 Some content
\ThisLRCornerWallPaper{1.0}{image.jpg}
\end{document} 

How can I use background image covering whole page?

Jesse
  • 29,686
manish
  • 9,111
  • 3
    Not having access to image.jpg I can only guess. You might try one of the images in \usepackage{mwe}. Anyway, \ThisLRCormenrWallPaper preserves the aspect ratio and will leave a margin on the left if it hits the top. To ignore the aspect ratio, use \ThisTileWallPaper{\paperwidth}{\paperheight}{image.jpg} – John Kormylo Mar 26 '14 at 03:39

3 Answers3

115

You can do this in number of ways. I will show three more methods.

With tikz:

\documentclass{article}
\usepackage{tikz}
\usepackage[top=2cm, bottom=2cm, outer=0cm, inner=0cm]{geometry}
\begin{document}
 Some content
\tikz[remember picture,overlay] \node[opacity=0.3,inner sep=0pt] at (current page.center){\includegraphics[width=\paperwidth,height=\paperheight]{example-image}};
\clearpage
text
\end{document}

With eso-pic:

\documentclass{article}
\usepackage{eso-pic,graphicx}
\usepackage[top=2cm, bottom=2cm, outer=0cm, inner=0cm]{geometry}
\begin{document}
 Some content
\AddToShipoutPictureBG*{\includegraphics[width=\paperwidth,height=\paperheight]{example-image}};
\clearpage
text
\end{document}

\AddToShipoutPictureBG (instead of \AddToShipoutPictureBG*) puts the background in all pages.

With background package:

\documentclass{article}
\usepackage[top=2cm, bottom=2cm, outer=0cm, inner=0cm]{geometry}
\usepackage[pages=some]{background}

\backgroundsetup{
scale=1,
color=black,
opacity=0.4,
angle=0,
contents={%
  \includegraphics[width=\paperwidth,height=\paperheight]{example-image}
  }%
}
\begin{document}
 \BgThispage
 Some content
 \clearpage
 text
\end{document}

enter image description here

Clokman
  • 103
  • 2
    Remark: the functionality of background is based on tikz. So, you show actually two methods. ;-) – Speravir Mar 27 '14 at 02:24
  • 1
    For those, like me, that came here looking for a solution for .Rmd, the second one works, however it will insert a ';' into the document asif it were a character, and can be removed. I'm not sure if this is a special operator that LaTeX sees and .Rmd doesn't. The geometry argument also doesn't seem to be required. – DaveRGP Jun 29 '16 at 08:45
  • What does * do at the end of \AddToShipoutPictureBG? – bkarpuz Jun 07 '17 at 21:56
  • 3
    @bkarpuz From the manual of eso-pic: "\AddToShipoutPictureBG* works like \AddToShipoutPictureBG but only for the current page. " – esdd Jun 14 '17 at 11:45
  • 1
    @DaveRGP: This ";" comes from the command, you can safely remove it. Likely just a copy & paste error – Uwe Ziegenhagen Oct 17 '17 at 05:02
  • 1
    The first way, with tikz, puts the background image on top of the page's content, which might not be what you want. The other two ways worked exactly as expected though. – Matthias Braun Aug 23 '20 at 19:11
  • The tikz way sometimes results with an image at the wrong height that would take onely like 10% of the page height instead of full height for me. Maybe it goes into a conflict with fancybox,fancyhdr packages. – Gherman Jul 11 '21 at 23:34
  • Is {{example-picture}} basically {{example-picture.jpg}}? – Christian Jan 09 '23 at 22:39
  • The background package gives me a fatal error about "Undefined control sequence. l.23 \pgfsyspdfmark". Can't figure out what that is. The \AddToHook solution from adam.baker below worked on the first try and didn't need imports. – Luc Jan 17 '23 at 09:21
12

Here is a solution that uses the (relatively) new \AddToHook macro.

\documentclass{article}
\usepackage{graphicx}
\usepackage{lipsum}

\AddToHook{shipout/background}{% \put (0in,-\paperheight){\includegraphics[width=\paperwidth,height=\paperheight]{mybg.pdf}}% }

\begin{document} \lipsum[1-5] \end{document}

(The background package now gives a warning because it uses deprecated macros.)

adam.baker
  • 1,116
1

Something I figured out that I looked a while for what how to skip a background image for a specific page. I have discovered the best way to do this is with:

\usepackage[pages=some]{background}
\backgroundsetup{
scale=0.1,
color=black,
opacity=0.1,
angle=0,
contents={%
  \includegraphics[width=\paperwidth,height=\paperheight]{Picture.png}
  }%
}

----- Page Wanting to Omit -----

Blah Blah Blah

\NoBgThispage % <------- Skips for current page \BgThispage % <------- Starts bg again for next page

Blah Blah Blah

Hope this helps someone.

Zirtzi
  • 11