1

This is what I am trying to do: I want to have a document written in Arial 12pt, with a half transparent background image centered in the first page, with customized margins.

This code compiled with XeLaTeX would be alright:

\documentclass[a4paper,12pt,oneside]{report}

\usepackage{graphicx}

\usepackage{fontspec}
\setmainfont{Arial}

\usepackage[pages=some]{background}
\backgroundsetup{
scale=1,
color=black,
opacity=0.2,
angle=0,
contents={%
  \includegraphics[width=\paperwidth,height=\paperheight]{ufpr_marcadagua.jpg}
  }%
}

\begin{document}

\BgThispage
\centerline{text}\par
more text
\clearpage

\end{document}

But when I reset the margins (code below) as I want the background image gets badly repositioned

\documentclass[a4paper,12pt,oneside]{report}

\usepackage{graphicx}

\usepackage{fontspec}
\setmainfont{Arial}

\setlength{\voffset}{-1in}
\setlength{\topmargin}{1cm}
\setlength{\headheight}{1cm}
\setlength{\headsep}{0.5cm}

\setlength{\hoffset}{-1in}
\setlength{\oddsidemargin}{2.5cm}
\setlength{\evensidemargin}{2.0cm}

\setlength{\textwidth}{16.5cm}
\setlength{\textheight}{25.2cm}
\setlength{\marginparsep}{0.5cm}
\setlength{\footskip}{1cm}

\usepackage[pages=some]{background}
\backgroundsetup{
scale=1,
color=black,
opacity=0.2,
angle=0,
contents={%
  \includegraphics[width=\paperwidth,height=\paperheight]{ufpr_marcadagua.jpg}
  }%
}

\begin{document}

\BgThispage
\centerline{text}\par
more text
\clearpage

\end{document}

How can I position the background image in the center of the page having reset margins?

5
  • Welcome to TeX.SX! Why don't you use geometry? Is there a reason to do it all manually?
    – TeXnician
    Commented Apr 25, 2017 at 17:20
  • The problem is quite certainly in setting \voffset and \hoffset
    – egreg
    Commented Apr 25, 2017 at 17:45
  • @TeXnician, it's just that I started doing this without the geometry package, and then I didn't want to use time to learn another way.
    – rodrikev
    Commented Apr 25, 2017 at 17:52
  • But as @egreg says this will probably change something. Try using it (you'll find easy guides on this site and in the documentation).
    – TeXnician
    Commented Apr 25, 2017 at 17:53
  • @egreg I get that, but if I change \voffset and \hoffset then I won't get the margins I want. Do you know of a way that I can position the background image at a specific distance from maybe the upper left corner of the textbox?
    – rodrikev
    Commented Apr 25, 2017 at 17:53

1 Answer 1

1

I prepared a PDF file which is just an A4 paper sheet with 12pt thick borders. Then I used your code with that picture, getting

enter image description here

You can see that the amount of shifting is exactly due to \hoffset and \voffset.

Never change their value in order to ease the setting of the page parameters.

Use geometry instead:

\documentclass[a4paper,12pt,oneside]{report}
\usepackage{geometry}
\usepackage{graphicx}
\usepackage[pages=some]{background}

\usepackage{fontspec}
\setmainfont{Arial}

\geometry{
  headheight=1cm,
  headsep=0.5cm,
  textwidth=16.5cm,
  textheight=25.2cm,
  heightrounded,
  marginparsep=0.5cm,
  footskip=1cm,
}

\backgroundsetup{
scale=1,
color=black,
opacity=0.2,
angle=0,
contents={%
  \includegraphics[width=\paperwidth,height=\paperheight]{a4paper.pdf}
  }%
}

\begin{document}

\BgThispage
\centerline{text}\par
more text
\clearpage

\end{document}

enter image description here

3
  • So what would you recommend?
    – rodrikev
    Commented Apr 25, 2017 at 17:54
  • @CRodrigues I added how to set the right dimensions with geometry.
    – egreg
    Commented Apr 25, 2017 at 17:57
  • Thanks @egreg. I'll try to shift to geometry. Anyway I did as you both said and changed margins using the other parameters and setting the offsets to zero.
    – rodrikev
    Commented Apr 25, 2017 at 18:06

You must log in to answer this question.

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