Recently I found out that the background
package is deprecated and one should use \AddToHook{shipout/background}
(comments in Positioning relative to page in XeLaTeX with package background and 'nested' tikzpictures 'dimension too large') and I have seen an example in this post: Migration background package > \AddToHook macro
However, for my use-case this conversion did not give the exact same results as the code written with background
package. I want to keep using relative coordinates with (0,0)
as the top-left of the page and (1,1)
the bottom-right of the page, as given in: Positioning relative to page in TikZ by romain.bqt4.
Code
\documentclass[12pt]{article}
\usepackage{tikz}
\usepackage{background}
\usepackage{lipsum}
\usepackage[centering, margin = 2cm, bottom = 2.5cm, top = 1.5cm, showframe]{geometry}
\usetikzlibrary{shapes.misc, positioning, calc}
\AddToHook{shipout/background}
{%
\put(1cm,-\paperheight)
{\begin{tikzpicture}[remember picture,shift=(current page.north west)] % for XeLaTeX
\begin{scope}[x={(current page.north east)},y={(current page.south west)}]
\node (logo) at (0.5, 0.95) {\piktjur};
\draw[rounded corners=10pt, line width = 2pt, red] (logo) -| (0.05, 0.025) -- (0.95, 0.025) |- (logo);
\end{scope}
\end{tikzpicture}}%
}
\SetBgAngle{0}
\SetBgScale{1}
\SetBgOpacity{1}
\SetBgContents{
\begin{tikzpicture}[remember picture,shift=(current page.north west)] % for XeLaTeX
\begin{scope}[x={(current page.north east)},y={(current page.south west)}]
\node (logo) at (0.5, 0.95) {\piktjur};
\draw[rounded corners=10pt, line width = 2pt, blue] (logo) -| (0.05, 0.025) -- (0.95, 0.025) |- (logo);
\end{scope}
\end{tikzpicture}
}
\newcommand*{\piktjur}{\includegraphics[height = 2cm]{example-image.pdf}}
\pagestyle{empty}
\begin{document}
hello
\end{document}
Now, ideally I would like them to patch and I believe it has something do with the
\put
command. However, if that is not possible, it also causes the problem of the relative coordinate system not working as it is supposed to work. Specifically, changing the logo node to for example (0.5, 0.925)
changes the height of the top horizontal part of the border. It even lowers the bar.
\AddToHook{shipout/background}
{%
\put(1cm,-\paperheight)
{\begin{tikzpicture}[remember picture,shift=(current page.north west)] % for XeLaTeX
\begin{scope}[x={(current page.north east)},y={(current page.south west)}]
\node (logo) at (0.5, 0.925) {\piktjur};
\draw[rounded corners=10pt, line width = 2pt, red] (logo) -| (0.05, 0.025) -- (0.95, 0.025) |- (logo);
\end{scope}
\end{tikzpicture}}%
}
Question
How do I need to change the code in order to:
- have the borders match,
- have the relative coordinate system working as expected?