23

When inserting a figure into a TeX document is there an easy way to make it appear behind the text?

Mike
  • 889

3 Answers3

24

You can put an image into zero width and zero height/depth box, so TeX will just runs over it. Also, you probably want to lower the figure since normally the reference point is at the bottom.

This works:

\documentclass{article}
\usepackage{graphicx,lipsum}
\pagestyle{empty}
\begin{document}
\noindent
\makebox[0pt][l]{%
  \raisebox{-\totalheight}[0pt][0pt]{%
    \includegraphics[width=4in]{book}}}%
\lipsum[1-2]


\end{document}

enter image description here

Boris
  • 38,129
  • 1
    This looks really good, thanks. The image is opaque right? Just want to be sure this puts it in the background not on top. Could the same trick put the graphic over the foreground? – Mike Feb 01 '14 at 00:54
  • The image is opaque. To put it on the foreground, just typeset it after the text – Boris Feb 01 '14 at 02:58
  • 2
    There is easier way. Just add negative space after the picture: \includegraphics[height=1\textheight]{picture} \vspace*{-1\textheight} (assuming the picture is the first thing on page) – Josef Kufner Dec 22 '15 at 10:54
  • 1
    I am not sure it is easier :) – Boris Dec 22 '15 at 18:35
18

You can use the background package. Initially, you use the pages=some option, so no background is initially used. Then on the page(s) in which you desire the image, you use the \BackImage command; its optional argument passes options to \includegraphics, and the mandatory argument contains the name of the image file:

\documentclass{article}
\usepackage[pages=some,scale=1,angle=0,opacity=0.7]{background}
\usepackage{graphicx}
\usepackage{lipsum}

\newcommand\BackImage[2][scale=1]{%
\BgThispage
\backgroundsetup{
  contents={\includegraphics[#1]{#2}}
  }
}

\begin{document}

\lipsum[2]
\BackImage[width=.5\textwidth]{example-image-a}% image on page 1
\lipsum[4-22]
\BackImage[width=.5\textwidth]{example-image-b}% image on page 4
\lipsum[3-4]

\end{document}

enter image description here

Using the available keys for \backgroundsetup you can easily change the attributes (opacity, position, scale, angle) of the included image.

In the case of a single image, it's enough to set contents to be the \includegraphics, pages=some and to use \BgThisPage for the page in which the image should be included.:

\documentclass{article}
\usepackage{graphicx}
\usepackage[pages=some]{background}
\usepackage{lipsum}

\backgroundsetup{
  scale=1,
  angle=0,
  opacity=0.7,
  contents={
    \includegraphics[width=\textwidth,height=4cm]{example-image-a}}
}

\begin{document}

\lipsum[1-20]
\BgThispage
\lipsum[3-4]

\end{document}
Gonzalo Medina
  • 505,128
9

You could also do this with tikz:

\documentclass[]{article}

\usepackage{pgfpages,tikz,lipsum}

\begin{document}

\begin{tikzpicture}[remember picture, overlay]
      \node[anchor=center] at (current page.center){%
        \pgfimage{example-image-a}};
\end{tikzpicture}

\lipsum[1-10]

\end{document}

which puts the background image only on the required page:

background picture with <code>tikz</code>

Or you might prefer to use wallpaper which offers the same functionality, as well as a way to repeat the image on every page:

\documentclass[]{article}

\usepackage{wallpaper,lipsum}

\begin{document}

\lipsum[1-10]
\ThisCenterWallPaper{1}{example-image-b}
%\CenterWallPaper{1}{example-image-b}% use this instead if you want the background repeated


\end{document}

which gives:

background image on single page with <code>wallpaper</code>

cfr
  • 198,882