2

I want to apply a background image to a document, but it seems to fail to cover the bottom and the right side of the pictures.

I started using the eso-pic example from here.

Simplifying my document I find that

\documentclass[a4paper,10pt]{article}

\usepackage{fullpage} 
\usepackage{eso-pic,graphicx}
\usepackage{hyperref}

\addtolength{\textwidth}{2cm}
\addtolength{\hoffset}{-1cm}
\addtolength{\textheight}{3cm}
\addtolength{\voffset}{-1.5cm}

\begin{document}

\AddToShipoutPictureBG*{
    \includegraphics[width=\paperwidth,height=\paperheight]{example-image-a}
};

\pagestyle{empty} % non-numbered pages

\end{document}

creates an image like below :

generated pdf where background fails to stretch

Where the white regions are the part of the page which are not covered by the image. How might I ensure the background image covers the entire page?

Strangely I fine that I can get rid of the bottom margin by removing the "\usepackage{hyperref}." This seems related to this question : Why does the hyperref package change the paper size?

However even without the hyperref package the right margin remains uncovered.

Cheers and thanks, Charles.

2
  • 1
    Welcome! If you set the page geometry with the geometry package (instead of \addtolength{\textwidth}{2cm} and so on), use \AddToShipoutPictureBG*{\AtPageLowerLeft{\includegraphics[width=\paperwidth,height=\paperheight]{example-image-a}}} and replace the ; e.g. by ~ it works.
    – user194703
    Nov 16, 2019 at 6:48
  • 1
    Try \documentclass[a4paper,10pt]{article} \usepackage{eso-pic,graphicx} \usepackage{hyperref} \usepackage[top=2cm, bottom=2cm, outer=0cm, inner=0cm]{geometry} \pagestyle{empty} \begin{document} \AddToShipoutPictureBG*{\AtPageLowerLeft{\includegraphics[width=\paperwidth,height=\paperheight]{example-image-a}}} ~ \end{document}
    – user194703
    Nov 16, 2019 at 6:50

1 Answer 1

1

You either need to correct for your adjustment of \hoffset and \voffset - the reason behind the white areas showing on the page, or you need to get rid of them altogether.

With \hoffset and \voffset adjustments:

\documentclass{article}

\usepackage{eso-pic,graphicx}

%\addtolength{\textwidth}{2cm}
\addtolength{\hoffset}{-1cm}
%\addtolength{\textheight}{3cm}
\addtolength{\voffset}{-1.5cm}

\begin{document}

\AddToShipoutPictureBG*{%
  \AtPageLowerLeft{%
    \hspace{1cm}% \hoffset adjustment
    \raisebox{-1.5cm}{% \voffset adjustment
      \includegraphics[width=\paperwidth,height=\paperheight]{example-image}% Background image
    }% \raisebox
  }% \AtPageLowerLeft
}% \AddToShipoutPictureBG*

\pagestyle{empty} % non-numbered pages

\mbox{}% Place something on the page in order for it to ship out

\end{document}

Without the \hoffset and \voffset adjustment:

\documentclass{article}

\usepackage{eso-pic,graphicx}

\begin{document}

\AddToShipoutPictureBG*{%
  \AtPageLowerLeft{%
    \includegraphics[width=\paperwidth,height=\paperheight]{example-image}% Background image
  }% \AtPageLowerLeft
}% \AddToShipoutPictureBG*

\pagestyle{empty} % non-numbered pages

\mbox{}% Place something on the page in order for it to ship out

\end{document}

The explicit placement of the background image \AtPageLowerLeft is not necessary, but it helps understand the code.

2
  • Thanks, this worked. I used the first suggestion because I wanted to keep the offset / width changes for my text formatting (not present in my sample). However I wonder if instead of using \textwidth \textheigh \voffset \hoffset there would there have been a better way increase the usable page size, keep the text centered without requiring the \hspace and \raisebox when adding the background. Nov 16, 2019 at 21:18
  • @CharlesGrandfield: Yes, there is a better way. Use the geometry package with the margin key-value. For example, \usepackage{geometry} \geometry{margin = 1cm}.
    – Werner
    Nov 16, 2019 at 22:31

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .