[Tex/LaTex] Centering of watermark at front page

horizontal alignmentwatermark

I have now modified the document to what I think is a MWE and also realized where it all goes wrong, but I still don't know why. Therefore I will update the post.

I am trying to make a watermark on the front page to be centered but have the problem that it ends up in the left side of the document. What is wrong with the coding? I have just used a precoded script and tried to insert my changes into that. The coding is

\documentclass{article}
\usepackage[firstpage]{draftwatermark}
\usepackage{tikz}
\SetWatermarkText{\tikz{\node[opacity=0.4]{\includegraphics{test_picture}};}}
\SetWatermarkAngle{0}
\SetWatermarkScale{1}
\SetWatermarkColor[rgb]{0,1,0}

\begin{document}
Test
\end{document}

Here it all works fine and the watermark is in the middle, but as I add this part

\usepackage{vmargin}
\setmarginsrb{2.5 cm}{1 cm}{2.5 cm}{2.5 cm}{1 cm}{1.5 cm}{1 cm}{1.5 cm}

It does not and the picture shrinks and ends up on the left. So my question is: what does this coding do, is it important for the rest of the document (I'm writing a report) and what can be done so that the watermark will end up in the right size and position?

Thank you!
Mikael

Best Answer

As you correctly identified, the error is introduced by vmargin. I had never heard of this package until now, and reading the description, it seems to have been superseded by geometry.

I'm not sure how vmargin works, because for some reason, it was changing the paper size. I tried to implement similar settings in geometry to produce a similar output, but geometry doesn't adjust the paper size when adjusting various heights and margins.

\documentclass{article}
\usepackage[firstpage]{draftwatermark}
\usepackage{graphicx}
\usepackage{tikz}
\usepackage[
  hmargin=2.5cm,
  vmargin={1cm,2.5cm},
  headheight=1cm,
  headsep=1.5cm,
  footskip=1.5cm,
]{geometry}

\SetWatermarkText{\tikz{\node[opacity=0.2]{\includegraphics{example-image-a}};}}
\SetWatermarkAngle{0}
\SetWatermarkScale{1}
\SetWatermarkColor[rgb]{0,1,0}

\begin{document}
Test
\end{document}

Here's the output:

output