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.)
15
  • 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, 2022 at 7: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, 2022 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 Dec 18, 2022 at 10:10
  • @samcarter_is_at_topanswers.xyz Is every tikzpicture a pgfpicture?
    – Evan Aad
    Dec 18, 2022 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, 2022 at 10:28

3 Answers 3

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

7
  • 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, 2022 at 11:16
  • 1
    as I wrote: \textheight is much larger then you expect. The green arrow starts at the bottom of the frame. Dec 17, 2022 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, 2022 at 11:23
  • 1
    add \pdfpageheight=20cm after \begin{document}. This will enlarge the mediabox and you can see the bottom. Dec 17, 2022 at 11:25
  • 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. Dec 17, 2022 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

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}
       \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}

enter image description here

6
  • 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, 2022 at 12:18
  • 1. 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, 2022 at 12:29
  • 1
    @EvanAad 1. + 2. Have a look at \addtobeamertemplate{...}{}{} Dec 18, 2022 at 12:31
  • 1
    3. \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) Dec 18, 2022 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, 2022 at 12:58

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .