1

How can I create globally named, page-immutable TikZ nodes, similar to the current page special node? I'll explain.

The kind of node I'd like to create is globally named in the sense that it has a name by which it can be referred to in every TikZ picture in which the options remember picture and overlay are "turned on".

It is page-immutable in the sense that when any of its anchors is accessed inside two tikzpicture environments: one whose content is eventually typeset on page x, and another one whose content is eventually typeset on a different page y, the anchor's coordinates are the same: if the anchor's coordinates were (1,3) on page x, they will again be (1,3) on page y.

The purpose of such nodes is to set up layout regions on every page relative to which elements of a TikZ picture can be positioned, for instance, a header region, a footer region, etc.

The package tikzpagenodes makes available several special nodes of the kind I described above. It makes available the nodes current page text area, current page marginpar area, current page header area, and current page footer area. However:

A. This list is closed. tikzpagenodes does not provide tools for creating other, user-defined special nodes of this kind.

B. While the layout engendered by the special nodes of the tikzpagenodes package is well adapted to documents of class article, it is not as well adapted to beamer presentations. I would like to create my own special nodes that would reflect more accurately the natural layout of beamer slides. (More about this can be found in this post and its comments.)

Evan Aad
  • 11,066
  • 2
    TikZ nodes already have those criteria: once defined they are globally defined, and if defined using remember picture their location on a page is fixed. – Andrew Stacey Dec 16 '22 at 16:47
  • 1
    You can also create a named local bounding box using a scope. – John Kormylo Dec 16 '22 at 16:49
  • @AndrewStacey Not true. The location on the page is not immutable in the sense I described in my post. – Evan Aad Dec 16 '22 at 17:04
  • @JohnKormylo Could you please explain in greater detail? – Evan Aad Dec 16 '22 at 17:05
  • @AndrewStacey On second inspection, it looks like you were right. I mean, the coordinates change a little from page to page, but only a little. If this is the case, then maybe this is all I need. – Evan Aad Dec 16 '22 at 17:23
  • 2
    The coordinates shouldn't change, but they might take a few complications to come to rest. When using a previously-defined node, TikZ has to convert its location to a position relative to the current picture's origin, but that might move while the picture's being created. – Andrew Stacey Dec 16 '22 at 17:43
  • Alas, named local bounding boxes are not saved globally. Never mind. – John Kormylo Dec 16 '22 at 18:07
  • These pseudo nodes are all nodes of shape rectangle. For every node a few macros are saved globally, one contains the shape name, one its transformation matrix, one the picture id and one the “saved macros”. For the rectangle node, the later contain only the south west and the north east anchor. (All other anchors can be calculated from them.) For the current page node, SW is the origin, NE ist pagewidth/height. The picture id is special, too: pgfpageorigin. If you know the measurements and the placement of your needed nodes, extra special nodes can be created. Do you know them? – Qrrbrbirlbel Dec 16 '22 at 19:21
  • This means, you need the coordinates in relation to the bottom left corner of the beamer page (provided the remember picture functionality works with beamer). – Qrrbrbirlbel Dec 16 '22 at 19:25
  • @Qrrbrbirlbel remember picture works the same way with beamer as in any other class. (Most of the scenes from https://vimeo.com/780457002 use beamer+remember picture :) ) – samcarter_is_at_topanswers.xyz Dec 16 '22 at 19:28
  • @samcarter_is_at_topanswers.xyz I figured as much but I didn't want to over promise and then have to realize that beamer might change something I don't understand. I can count my usages of beamer on one hand. – Qrrbrbirlbel Dec 16 '22 at 19:33
  • @Qrrbrbirlbel No, I don't know them. I'll probably need to do manual experimentation and judging by eyesight, like John Kormylo did in a now deleted answer to another question of mine. The most difficult element to estimate by eyesight is the height of the shade under the title, because the cutoff point between shade and non-shade is very hard to pin down. – Evan Aad Dec 16 '22 at 20:23

2 Answers2

4

What I can see from tikzpagenodes, you use \@newtikzpagenode that takes two \pgfpoints - \southwest and \northeast.

Here is the code from tikzpagenodes.sty defining just (current page text area):

\documentclass{article}
\usepackage{tikz}
\usepackage[showframe]{geometry}
\makeatletter
\NeedsTeXFormat{LaTeX2e}[1999/12/01]
\RequirePackage{tikz}
\RequirePackage{ifoddpage}
\tikzset{every picture/.append style={execute at begin picture={%
    \ifpgfrememberpicturepositiononpage
        \checkoddpage
    \fi
}}}
\def\currentsidemargin{\ifoddpageoroneside\oddsidemargin\else\evensidemargin\fi}%
\def\current@textarea@left{(1in+\hoffset+\currentsidemargin)}
\def\current@textarea@top{(1in+\voffset+\topmargin+\headheight+\headsep)}
\def\@newtikzpagenode#1{%
    \expandafter\let\csname pgf@sh@ns@#1\expandafter\endcsname\csname pgf@sh@ns@current page\endcsname
    \expandafter\let\csname pgf@sh@nt@#1\expandafter\endcsname\csname pgf@sh@nt@current page\endcsname
    \expandafter\let\csname pgf@sh@pi@#1\expandafter\endcsname\csname pgf@sh@pi@current page\endcsname
    \expandafter\def\csname pgf@sh@np@#1\endcsname
}
\@newtikzpagenode{current page text area}{%
    \def\southwest{\pgfpoint{\current@textarea@left}{\paperheight-\current@textarea@top-\textheight}}%
    \def\northeast{\pgfpoint{\current@textarea@left+\textwidth}{\paperheight-\current@textarea@top}}%
}
\makeatother
\begin{document}
\begin{tikzpicture}[overlay, remember picture]
\draw[red, thick] (current page text area.north west) circle[radius=10pt];
\end{tikzpicture}
\end{document}

Top of page with lines and a red circle

0

Thanks to Andrew Stacey's comment, I've realized I can achieve my goals by creating in the first page/slide a simple, empty node of the desired position and dimensions, as demonstrated in the following LaTeX code.

\documentclass{beamer}
\usepackage{tikz}
\begin{document}

\begin{frame}{First Frame} \tikz [remember picture, overlay] \node [ inner sep = 0pt, anchor = center, minimum width = 2cm, minimum height = 2cm ] (current text area) at (current page.center) {} ; Hello, world! \end{frame}

\begin{frame}{Second Frame} The end! \begin{tikzpicture} [remember picture, overlay] \draw [fill] (current text area.south west) circle (2pt); \draw (current text area.north east) circle (3pt); \end{tikzpicture} \end{frame}

\end{document}

The PDF generated by this code is as follows.

An invisible, auxiliary layout node

Evan Aad
  • 11,066