3

I saved the following LaTeX code in the file ~\Test.tex.

\documentclass{beamer}
\usepackage{tikz}
\usetheme{Warsaw}
\begin{document}
\begin{frame}{Frame Title}
    \begin{tikzpicture}
       \draw[fill,red](0,0)rectangle(\textwidth,\textheight);
       \draw[fill,orange](0,0)circle(2pt);
       \draw[fill,orange](\textwidth,\textheight)circle(2pt);
    \end{tikzpicture}
\end{frame}
\end{document}

The code creates a beamer presentation whose theme is Warsaw. (The Warsaw theme adds headers and footers to every frame.) The presentation consists of a single, regular frame. The frame's content consists of a single object: a TikZ picture. The picture is composed of three elements: a filled red rectangle whose width is \textwidth and whose height is \textheight, and two filled orange circles at the bottom left and top right corners of the red rectangle.

I then executed the following commands in the Terminal.

> cd ~
> lualatex Test
> lualatex Test

At the end of the compilation ~/Test.log did not contain any instructions to rerun the compilation. The compilation resulted in the creation of the file ~/Test.pdf. When opened in a PDF viewer, the file displayed as follows.

A beamer slide with a red rectangle

As can be seen, the orange circle at the top right corner of the red rectangle is visible, but the one at the bottom left corner is invisible. This indicates that part of the red rectangle is hidden behind the black and blue footer.


Questions

  1. How can the red rectangle be drawn in front of the footer?
  2. More generally, how can a TikZ picture be drawn in front of any other TikZ picture that overlaps it, even without knowing which TikZ pictures, if any, actually overlap it, or even if there are any other TikZ pictures in the document?
  3. Even more generally, how can a PGF picture be drawn in front of any other PGF picture? (Apparently the footer of a beamer presentation of the Warsaw theme is not a TikZ picture, but a PGF picture. Moreover, every TikZ picture is a PGF picture, but not vice versa.)
Evan Aad
  • 11,066
  • You could try the options remember picture, overlay. The second option puts the picture out of the text-segment and on top of it. Now, if you create the picture in the beamer context, it will not cover the footer, I think. – Daniel N Dec 17 '22 at 07:12
  • @DanielN This trick changes the position of the red rectangle on the page. I don't wish the position of the TikZ picture to change. I simply want it to become visible in full. – Evan Aad Dec 17 '22 at 10:16
  • Your question is misleading. Do you want the tikzpicture in front of other tikzpictures or in front of other elements on the page? The footline is not a tikzpicture. The theme you choose uses a pgfpicture for the footline – samcarter_is_at_topanswers.xyz Dec 18 '22 at 10:10
  • @samcarter_is_at_topanswers.xyz Is every tikzpicture a pgfpicture? – Evan Aad Dec 18 '22 at 10:13
  • @DanielN What I think happens when you give the overlay option to a drawing command is that the command's drawing takes place in a layer that "sits" on top of all other layers. This layer is unique throughout a LaTeX document: if two commands in two different tikzpicture environments are given the overlay option, they both draw on the same top-level layer. However, different tikzpicture environments set up different systems of coordinates on this top layer. Those systems of coordinates are local to each tikzpicture environments. – Evan Aad Dec 18 '22 at 10:28
  • @DanielN So, if you write \draw[overlay](0,0)circle(1cm); in two different tikzpicture environments, both circles will be drawn on the top layer, but possibly at different locations on the top layer: the first circle will be drawn about the point (0,0) w.r.t. the coordinate system set up locally by the first tikzpicture environment, whereas the second circle will be drawn about the point (0,0) w.r.t. the coordinate system set up locally by the second tikzpicture environment. – Evan Aad Dec 18 '22 at 10:29
  • @DanielN And if the origins of these two systems of coordinates are mapped to two different points of the top level layer, then two distinct circles will get drawn. – Evan Aad Dec 18 '22 at 10:29
  • @EvanAad Normally yes, but with latex there is always at least one user who does something unusual, so I wouldn't be surprised if someone redefined the tikzpicture. – samcarter_is_at_topanswers.xyz Dec 18 '22 at 10:29
  • The statement "adds headers and footers to every frame, except the title frame or other special frames" is also not true. Head and footline are added to all frames unless you switch them off, e.g. with the plain option. Beamer does not automatically disable them for the title page. – samcarter_is_at_topanswers.xyz Dec 18 '22 at 10:31
  • @DanielN (continuing my last comment) This is why, when the overlay option is added to the tikzpicture environment in the code listed in my question, the red rectangle changes position: the overlay option changes the environment's local coordinate system, or more accurately, it changes the mapping of the environment's local coordinate system to absolute positions on the physical page. – Evan Aad Dec 18 '22 at 10:47
  • @DanielN The million dollar question is: why does the overlay option cause this change of mapping? I don't have an answer to this question. – Evan Aad Dec 18 '22 at 10:55
  • @samcarter_is_at_topanswers.xyz I've amended my question per your corrections. I hope now it's not misleading. – Evan Aad Dec 18 '22 at 11:01
  • The title is still misleading. There aren't any other tikzpictures on your page, so your tikzpicture is automatically in front of all other tikzpictures. – samcarter_is_at_topanswers.xyz Dec 18 '22 at 11:11
  • @samcarter_is_at_topanswers.xyz I've corrected the title. – Evan Aad Dec 18 '22 at 11:17

3 Answers3

5

If you want to print some thing on top off everything you have to add it after the footer. You can e.g. use the shipout/foreground hook. When calculating the sizes, be aware that \textheight in beamer is much larger than you expect. It actually goes down to the bottom of the frame.

\documentclass{beamer}
\usepackage{tikz}
\usetheme{Warsaw}
\begin{document}
\makeatletter
\AddToHook{shipout/foreground}{%
  \put(1cm,-\paperheight){%
       \begin{tikzpicture}
       \draw[fill,red,use as bounding box](0,0)rectangle(\textwidth,\paperheight);
       \draw[fill,orange](0,0)circle(2pt);
       \draw[fill,orange](\textwidth,\paperheight)circle(2pt);
       \draw[<->,green,line width=3pt](-2pt,0)--++(0,\textheight);
       \end{tikzpicture}}
       }
\begin{frame}[t]{Frame Title}
\mbox{}
\end{frame}
\end{document}

enter image description here

enter image description here

enter image description here

Ulrike Fischer
  • 327,261
  • Thank you. Why does the green arrow protrude into the header? In my example the red rectangle doesn't overlap the header. – Evan Aad Dec 17 '22 at 11:16
  • 1
    as I wrote: \textheight is much larger then you expect. The green arrow starts at the bottom of the frame. – Ulrike Fischer Dec 17 '22 at 11:21
  • In my example, where is the (hidden) bottom of the red rectangle? Along the bottom of the page? – Evan Aad Dec 17 '22 at 11:23
  • 1
    add \pdfpageheight=20cm after \begin{document}. This will enlarge the mediabox and you can see the bottom. – Ulrike Fischer Dec 17 '22 at 11:25
  • I see. Then in my example the hidden bottom of the red rectangle is below the bottom of the footer, whereas in your example the bottom of the red rectangle is along the bottom of the footer. Then it's not the same red rectangle. Your code did more than merely send the red rectangle to the front; it changed the dimensions of the red rectangle. – Evan Aad Dec 17 '22 at 11:31
  • Or changed its position. Or both. – Evan Aad Dec 17 '22 at 11:39
  • 1
    I put the zero point of the picture at the bottom left (+1cm in x direction): \put(1cm,-\paperheight). The zero point of the hook is at the top left. – Ulrike Fischer Dec 17 '22 at 11:52
3

I'd like to suggest a variation on Ulrike Fischer's answer. The variation avoids the \put command, and instead positions the elements of the TikZ picture relative to the current page pseudo-node.

\documentclass{beamer}
\usepackage{tikz}
\usetikzlibrary{calc,math}
\usetheme{Warsaw}
\begin{document}
\AddToHook{shipout/foreground}{%
   \begin{tikzpicture}[remember picture, overlay]
      \tikzmath{
         coordinate \origin;
         \origin = (current page.south west) + (1,0);
      }
      \draw[fill,red](\origin)rectangle++(\textwidth,\paperheight);
      \draw[fill,orange](\origin)circle(2pt);
      \draw[fill,orange]($(\origin)+(\textwidth,\paperheight)$)circle(2pt);
      \draw[<->,green,line width=3pt]($(\origin)+(-2pt,0)$)--++(0,\textheight);
   \end{tikzpicture}%
}
\begin{frame}{Frame Title}
\end{frame}
\end{document}

The output in both cases is the same:

The output

Evan Aad
  • 11,066
2

If you look at Figure 1 of the beamer user guide, you'll see that the footline is drawn as the very top layer of a beamer frame. If you don't want it from covering your frame content, you can use a layer further down to show the footline.

enter image description here

\documentclass{beamer}
\usetheme{Warsaw}
\usepackage{tikz}

\setbeamertemplate{footline}{\vskip3.625ex}

\makeatletter \setbeamertemplate{sidebar canvas left} {% \tiny% \leavevmode% \hbox{% \rule{0pt}{\dimexpr\paperheight-1.125ex}% \hbox{\begin{beamercolorbox}[wd=.5\paperwidth,ht=2.5ex,dp=1.125ex,leftskip=.3cm plus1fill,rightskip=.3cm]{author in head/foot}% \usebeamerfont{author in head/foot}\insertshortauthor \end{beamercolorbox}% \begin{beamercolorbox}[wd=.5\paperwidth,ht=2.5ex,dp=1.125ex,leftskip=.3cm,rightskip=.3cm plus1fil]{title in head/foot}% \usebeamerfont{title in head/foot}\insertshorttitle\nobreak\hfill\usebeamercolor[fg]{page number in head/foot}\usebeamerfont{page number in head/foot}\usebeamertemplate{page number in head/foot} \end{beamercolorbox}}}% \vskip0pt% } \makeatother

\begin{document} \begin{frame}{Frame Title} \begin{tikzpicture} \drawfill,redrectangle(\textwidth,\textheight); \drawfill,orangecircle(2pt); \drawfill,orangecircle(2pt); \end{tikzpicture} \end{frame} \end{document}

enter image description here

  • Thanks. For future reference: the figure appearing in the beginning of your answer is taken from section 8.2 Components of a Frame on p. 62 of The BEAMER class User Guide for version 3.68 (the current version). – Evan Aad Dec 18 '22 at 12:18
  • Does beamer provide hooks for executing code at the start or end of one of the beamer layers illustrated above? Or a way of appending code to the beginning and end of each of these layers? 2. The same question, but w.r.t. templates, such as the headline template. 3. Is it possible to create a new template e.g. for the headline, that calls the theme's template for this element without knowing its internals, much like it is possible to call a LaTeX macro by name without knowing the details of its implementation?
  • – Evan Aad Dec 18 '22 at 12:29
  • 1
    @EvanAad 1. + 2. Have a look at \addtobeamertemplate{...}{}{} – samcarter_is_at_topanswers.xyz Dec 18 '22 at 12:31
  • 1
  • \usebeamertemplate{...}, but you don't want to blindly insert templates into other ones. You need to adapt them to the situation (fontsize/positioning/current mode)
  • – samcarter_is_at_topanswers.xyz Dec 18 '22 at 12:32
  • A template's content is drawn/typeset inside a bounding box, right? Is there a way to tell the size and position on the page of this box? For instance, suppose I'd like to know the size and position on the page of the headline box. Can I query these pieces of information inside the third pair-of-braces of addtobeamertemplate{headline}{}{}? – Evan Aad Dec 18 '22 at 12:58
  • Place a tikzmark at the bottom of the headline and you'll know its position. No need to know the actual height. Or use the \headheight – samcarter_is_at_topanswers.xyz Dec 18 '22 at 13:03