TransWikia.com

Background images leave a border

TeX - LaTeX Asked by user66094 on September 2, 2021

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}
newcommandBackgroundPic{%
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?

One Answer

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.2paperwidth,height=paperheight,keepaspectratio]{background.jpg}
    

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

Correct answer by epR8GaYuh on September 2, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP