Tikz-Pgf – Centering Rotated TikZ Watermark on Page

tikz-pgfwatermark

I am attempting to add watermarks to a document using TikZ and LaTeX's hooks.

I have attempted to do by adapting @Skillmon's code from: https://tex.stackexchange.com/a/615832/181010.

In doing so I arrived at the following:

\documentclass{article}

\usepackage{tikz}

\AddToHook{shipout/foreground}{%
    \put(0.5\paperwidth,-0.5\paperheight){\mywatermark}%
}

\newcommand*\mywatermark{\usebox\mywatermarkbox}

\newsavebox\mywatermarkbox
\tikzset{mywatermark/.style={color=gray,
                             opacity=0.65,
                             rotate=#1,
                             font=\fontsize{60}{66}\selectfont\sffamily}}

\AtBeginDocument{%
    \sbox\mywatermarkbox{%
        \makebox[0pt]{\tikz\node[mywatermark=45]{GLOBAL MEGACORP};}%
    }%
}

\usepackage{duckuments}

\begin{document}
\duckument
\end{document}

However, in increasing the font size the text no longer appears centered on the
page (see image below).

first page of MWE

How could I adapt this code to ensure that the watermark is visually centered
on the page?


I suspect this issue is related to the point around which rotation is
performed. I have tried amending this point using the rotate around key, but
to no avail.

Best Answer

A picture created by tikz has its baseline by default at the bottom. So if you rotate the node the baseline will be always at the lower left.

You can change the baseline with the baseline key:

\RequirePackage{fix-cm}
\documentclass{article}

\usepackage{tikz}

\AddToHook{shipout/foreground}{%
    \put(0.5\paperwidth,-0.5\paperheight){\mywatermark}%
}

\newcommand*\mywatermark{\usebox\mywatermarkbox}

\newsavebox\mywatermarkbox
\tikzset{mywatermark/.style={color=gray,
                             opacity=0.65,                             
                             rotate=#1,
                             font=\fontsize{60}{66}\selectfont\sffamily}}

\AtBeginDocument{%
    \sbox\mywatermarkbox{%
        \makebox[0pt]{\tikz[baseline=(wm.center)]\node[mywatermark=45](wm){GLOBAL MEGACORP};}%
    }%
}

\usepackage{duckuments}

\begin{document}
\duckument
\end{document}

enter image description here

Related Question