[Tex/LaTex] backgroundsetup and tikzpicture placement

backgroundspositioningtikz-pgf

I'm trying to put a tikzpicture on a (titlepage) using background page. Now, if I put some text content instead, it works as expected (centered on page).
But if I use tikzpicture (with a sample rectangle) it looks like the tikzpicture's 0,0 coordinates are at center, not at top left. That's not a big problem except when using page for positioning (i.e. (current page.west) won't work).
Am I missing something obvious? How would I put a border around the page?

This is a sample with hardcoded coordinates that centers my rectangle on page.

\documentclass[a4paper]{article}
\usepackage{geometry}
\usepackage{xcolor}
\usepackage{background}
\usepackage{tikz}
\usetikzlibrary{calc,matrix,shapes.geometric}
\usepackage{pgfmath,pgffor}

\definecolor{titlepagecolor} {cmyk}{0.6262,0.5157,0.4597,0.3977}

\backgroundsetup{
    placement=center,
    scale=1,
    angle=0,
    opacity=1,
    nodeanchor=center,
    contents={
        \begin{tikzpicture}[remember picture,overlay]
            \path [fill=titlepagecolor] (-5, -5) rectangle (5, 5);
        \end{tikzpicture}
    }
}
\makeatletter

\begin{document}
\begin{titlepage}
\BgThispage

%\phantom{wbweb}
\end{titlepage}
Hello
\end{document}

Update (my output from @Alenanno's code]). I'm using TexStudio/XeLaText on Windows if this matters.
My output from @Alenanno's code

Update: Looks like an issue with XeLaTex only.

Best Answer

Not sure what your problem is, current page.#anchor should work, and using your code, it worked for me. If you only want to put a frame, then you need to \draw a rectangle, as opposed to a \fill.

I've made it so that the rectangle will increase its thickness towards the center, if you want to change it. So none of the rectangle goes outside of the page (the light grey border you see is part of the preview of the page in the application).

Misplacement with xelatex

As explained in the question fontspec and background, the content of background is in a node. So you have two solutions:

  1. Don't use background. After all, you need this in one page only, so enclose the whole tikzpicture in a new command called \mycover, for example, and then add that to the document.
  2. Use the eso-pic package, although I've never used this one so you should check the documentation.

I think the first solution is the easiest and fastest to adopt.

Output

enter image description here

Code

\documentclass[a4paper]{article}
\usepackage{geometry}
%\usepackage{xcolor}
%\usepackage{pgfmath,pgffor} % these two are not needed (i.e. already loaded) with your current setup
\usepackage{background}
\usepackage{lipsum} % for lorem ipsum
\usepackage{tikz}
\usetikzlibrary{calc,matrix,shapes.geometric}

\definecolor{titlepagecolor}{cmyk}{0.6262,0.5157,0.4597,0.3977}

\backgroundsetup{
    placement=center,
    scale=1,
    angle=0,
    opacity=1,
    nodeanchor=center,
    contents={
        \begin{tikzpicture}[remember picture,overlay]
            %\path [fill=titlepagecolor] (-5, -5) rectangle (5, 5);
            \draw[titlepagecolor, line width=1cm] 
                ($(current page.north west)+(.5\pgflinewidth,-.5\pgflinewidth)$) rectangle 
                ($(current page.south east)+(-.5\pgflinewidth,.5\pgflinewidth)$);
        \end{tikzpicture}
    }
}
\makeatletter

\begin{document}
\begin{titlepage}
\BgThispage

%\phantom{wbweb}
\end{titlepage}
\lipsum[1-6]
\end{document}