0

Having to put a background image for the title page of a book I've used the following lines in the preamble:

\usepackage{tikz}
\usetikzlibrary{positioning}
\usepackage{xcolor}
\usepackage{graphics}
\usepackage{eso-pic}
\newcommand\BackgroundPic{%
\put(0,0){%
\parbox[b][\paperheight]{\paperwidth}{%
\vfill
\centering
\includegraphics[width=\paperwidth,height=\paperheight,%
keepaspectratio]{background.jpg}%
\vfill
}}}

and then this right after the \begin{document}:

\AddToShipoutPicture*{\BackgroundPic}

(The code has been taken from here: How to create a background image on title page with LaTeX?)

The image was indeed loaded but it leaves a white border above and below, as you can see in the screenshot, which I would like to erase. enter image description here

Can anyone help me?

3
  • 1
    I have not tested it, but the keepaspectratio option might be the culprit if the aspect ratio of your document and your image do not match.
    – epR8GaYuh
    Jul 25, 2020 at 19:15
  • This worked, thank you very much
    – user66094
    Jul 25, 2020 at 19:33
  • I have expanded my comment into a proper answer.
    – epR8GaYuh
    Jul 26, 2020 at 8:10

1 Answer 1

2

The

\includegraphics[width=\paperwidth,height=\paperheight,keepaspectratio]{background.jpg}

command uses the keepaspectratio option which might induce such whitespace if the aspect ratio of the document and the image do not match.

There are multiple solutions for this:

  1. Remove the keepaspectratio option. This will stretch the image in the Y dimension in your case. As it will leave you with a distorted image, this might not be the best option.

  2. Use an image whose aspect ratio matches the one of the document. This might be hard depending on your document.

  3. Scale the image to fit the document, for example using something like

    \includegraphics[width=1.2\paperwidth,height=\paperheight,keepaspectratio]{background.jpg}
    

    Please note that this solution will give you a "Overfull \hbox" warning. Additionally some content will be hidden.

1
  • Thanks very much for the solution. When you first commented I went for the first suggestion and since there wasn't such a blank space, there wasn't any distortion(or it was minimal anyway). As for the third one I have to say that it doesn't work: it doesn't lead to an error but nothing changes nevertheless, I don't know why that may be.
    – user66094
    Jul 26, 2020 at 20:18

You must log in to answer this question.

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