1

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.

enter image description here

On page 2, the rules are in vertical mode, MIDDLE is lower, which I don't want

enter image description here

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?

  • well in your example you additionally use center, which is a list, and so the paragraph started by your rule adds also list space. Imho it is very hard to control and undo such spaces, so better try to control where your command is placed. E.g. you could use the shipout hooks instead. – Ulrike Fischer Oct 08 '21 at 10:08
  • @UlrikeFischer Thx, I followed the shipout idea \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

0 Answers0