2

How can I put the content of pgf images behind the title bar? I tried to use How to insert a background image in a beamer frame? but this fails if the frame has animations, and pgfonlayer does not seem to help.

enter image description here

MWE

\documentclass[]{beamer}
\usepackage{tikz}
\usepackage[most]{tcolorbox}
\usetikzlibrary{backgrounds}

% Frame title
\defbeamertemplate*{frametitle}{ubuntu}[1][]
{%
  \begin{tcolorbox}[enhanced,sharp corners,spread upwards,frame hidden,boxrule=0pt,interior style tile={width=\paperwidth}{example-image-a},before skip=0pt,halign=center]
    \usebeamercolor{frametitle}\color{fg}
    \insertframetitle
  \end{tcolorbox}
}

\begin{document}

%% FRAME_START
\begin{frame}{Foo}
    \begin{tikzpicture}[overlay,remember picture]
    \begin{pgfonlayer}{background} % <--- this does not help, even if I wrap the tcolorbox inside a tikzpicture
      \draw[fill=red] ([shift={(5mm,-5mm)}]current page.north west) rectangle (current page.south east);
      \node<+-> at (current page.center) {I'd like this picture to be behind the header.};
      \node<+-> at ([yshift=-1cm]current page.center) {And I want to be able to put pauses in my picture like this.};
    \end{pgfonlayer}
  \end{tikzpicture}  
\end{frame}

\end{document}
2

1 Answer 1

1

The background layer of a tikzpicture is still part of that picture. It doesn't magically sink behind stuff not in the picture - just as the background of a painting doesn't sink behind the canvas.

To put stuff in the background of a slide, you need Beamer methods --- not TikZ. See the Beamer manual for details of the various layers available. In addition to background canvas, background may be of interest.

You want to set (after, possibly, defining) the relevant Beamer template - just as you do for the title element.

Here's an example which shows how to define and set the background canvas with and without TikZ. For simple shading or a block of colour, use Beamer's methods. For more sophisticated effects, use a tikzpicture or similar.

\documentclass[]{beamer}
\usepackage{tikz}
\usepackage[most]{tcolorbox}

% Frame title
\defbeamertemplate*{frametitle}{ubuntu}[1][]
{%
  \begin{tcolorbox}[enhanced,sharp corners,spread upwards,frame hidden,boxrule=0pt,interior style tile={width=\paperwidth}{example-image-a},before skip=0pt,halign=center]
    \usebeamercolor{frametitle}\color{fg}
    \insertframetitle
  \end{tcolorbox}%
}
\defbeamertemplate{background canvas}{red box}{\color{red}\vrule width\paperwidth height\paperheight}

\begin{document}

\setbeamertemplate{background canvas}[red box]
%% FRAME_START
\begin{frame}{Foo}
    \begin{tikzpicture}[overlay,remember picture]
      \node<+-> at (current page.center) {I'd like this picture to be behind the header.};
      \node<+-> at ([yshift=-1cm]current page.center) {And I want to be able to put pauses in my picture like this.};
  \end{tikzpicture}  
\end{frame}
\setbeamertemplate{background canvas}{% use a minipage if you don't want the image to occupy the whole area - you probably want to set background rather than background canvas in this case
%   \begin{minipage}[t]{\paperwidth}
    \includegraphics[height=\paperheight,width=\paperwidth]{example-image-a}%
%   \end{minipage}%
}
\begin{frame}{Image}
  With an image.
\end{frame}
\setbeamertemplate{background canvas}{%
  \begin{tikzpicture}[x=\paperwidth,y=\paperheight]
    \fill [left color=blue,right color=green] (0,0) rectangle (1,1);
    \foreach \i [evaluate=\i as \j using int(\i+2)] in {0,2,4,6,8} \fill [white,opacity=\i/10] (0,\i/10) rectangle (\paperwidth,\j/10);
  \end{tikzpicture}%
}
\begin{frame}{Pic}
  With a picture.
\end{frame}
\setbeamertemplate{background canvas}[default]
\begin{frame}{Default}
  Sans.
\end{frame}

\end{document}

Due to an Okular bug no images are available for the present. My apologies for depriving readers of a viewing of example-image-a.

There's no issue with pauses and such - none of this affects the content of the frame.

4
  • Thanks, sadly it does not solve my actual issue, as I want different background images when I go to the next slide, so I can't separate the background from the text as you did to keep the animation inside the frame…
    – tobiasBora
    Apr 4 at 6:22
  • (And good to know that layers are local to the picture, I always thought is was global somehow, exploiting some z-index like pdf primitives)
    – tobiasBora
    Apr 4 at 6:24
  • 1
    @tobiasBora Then I am fairly sure you are out of luck. The background and background canvas are not part of the content of the frame environment, which is why you need to set them before the frame begins. I would use plain in a case such as the one you describe and use the entire available area for the images rather than including the header etc. Or else you'd have to make them separate frames, I think. (Or maybe hack into Beamer - don't know.)
    – cfr
    Apr 4 at 12:59
  • 1
    @tobiasBora No z-index. TikZ doesn't have the concept. That's why you can externalise a layered picture. (You can't externalise one with remember picture because it does hook into the PDF stuff, but layers are all just the order of drawing.)
    – cfr
    Apr 4 at 13:02

You must log in to answer this question.

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