When using tikz to make an overlay picture, one may use for example
\tikz[overlay,remember picture] at (current page.center} {CENTER};
It will print "CENTER" at the center of the page. However the output really depends on where this instruction is located.
In next MWE the above command is emulated by \rule{0pt}{0pt}. If this instruction is located in horizontal mode, its effect is null but when located in vertical mode, it adds some extra vertical space which I want to avoid when there will be no horizontal material.
\documentclass{article}
\RequirePackage[paperwidth=3cm,paperheight=3cm]{geometry}
\begin{document}
\begin{center}PAGE 1\rule{0pt}{0pt}\end{center}%
\begin{center}MIDDLE\rule{0pt}{0pt}\end{center}%
AFTER
\newpage
\begin{center}PAGE 2\end{center}%
\rule{0pt}{0pt}%
\begin{center}MIDDLE\end{center}
\rule{0pt}{0pt}%
AFTER
\newpage
\begin{center}PAGE 3\end{center}%
\vskip-2\lastskip
\rule{0pt}{0pt}%
\begin{center}MIDDLE\end{center}
\rule{0pt}{0pt}%
AFTER
\end{document}
On page 1, the rules are in horizontal mode, no effect.
On page 2, the rules are in vertical mode, MIDDLE is lower, which I don't want
Page 3 is similar to Page 1 due to the \vskip only before the first \rule.
The question is how to automatically find the proper amount of vertical space to unskip depending on the situation?


\NewHook {MyHook} \AddToHook{shipout/background}{\put(0pt,0pt){% \UseHook{MyHook}% \RemoveFromHook{MyHook}[*]% }}Feeding MyHook works fairly well for articles but fails for beamer class, which is not very surprising! Is there a workaround? – Jérôme LAURENS Oct 08 '21 at 12:00