3

TL;DR: I want LaTeX Beamer to lay out elements in a frame exactly as usual, but give me the final say about the order in which overlapping elements occlude each other.

Some context

  • In CSS, the z-index of an element specifies its position on the axis into or out of the screen. An element with z = 0 is occluded by an overlapping element with z = 1, regardless of where in the CSS code the two elements are defined relative to each other.

  • In MS PowerPoint's GUI, it is trivial for an element to be "moved to front" and "moved to back".

For LaTeX Beamer, I can only find one 7-y/o thread about this issue, and it is clearly unsatisfactory w.r.t. the above two descriptions of z-index: the answer messes with the background theme, and doesn't actually allow to specify a z-index.

Goal

I have fairly standard Beamer frame code that puts this image under some equation text. The placement is good, but the text and image overlap slightly. Although the image is white where they overlap, Beamer doesn't want to put the image behind my text. Hence, some of it is occluded.

I want to customise their order, whilst using the same environments etc. that I have used. Ideally, I'd wrap some of my code in an unintrusive \zindex{index}{content}. Even better: a z-index option for the existing environments. Wrapping them in a TikZ picture will probably not work, because that means I have to deal with x-y positioning, which Beamer does correctly already.

I'm quite surprised this isn't a standard Beamer feature. In my experience, it's not uncommon for PDF figures to have plenty of white space near one of their corners, allowing for overlap there without creating an ugly, "PowerPoint-ian" collage.

Two MWEs with their outputs

The following MWE contains the code I'd like to alter minimally:

%%% DOCUMENT %%%
\documentclass{beamer}
\usetheme{Antibes}
\usebeamercolor{dolphin}

%%% IMPORTS %%%
\usepackage{mathtools}
\usepackage{tikz}

%%% MAIN %%%
\begin{document}
\title{Stochastics and statistics -- Slides}
\section{Stochastic variables}
\subsection{Transformations}

\begin{frame}
    \frametitle{Example of linear transform}
    % Equations
    \begin{align*}
        f_X(x) &= \begin{dcases}
            e^{-x} \qquad &(x\geq 0)\\
            0 \qquad &(x<0)
        \end{dcases}\\
        &\Bigg\downarrow\qquad Y = 2X + 1 \quad\Leftrightarrow\quad X = \frac{Y-1}{2}\\
        f_Y(y) &= \begin{dcases}
            \frac{1}{2} e^{-\frac{y-1}{2}} \qquad &(y\geq 1)\\
            0 \qquad &(y < 1)
        \end{dcases}
    \end{align*}    
    \vspace{-1.5cm}
    % Figure and warning    
    \begin{columns}\hspace{0.5cm}
        \begin{column}{0.5\paperwidth}
            \begin{figure}
                \centering
                \includegraphics[width=\linewidth]{fig/graph}
            \end{figure}
        \end{column}
        \begin{column}{0.425\paperwidth}
            \begin{itemize}
                \item Warning: don't forget to transform the bounds!
            \end{itemize}
        \end{column}
    \end{columns}
\end{frame}

\end{document}

Bad order

The following MWE contains the very unpractical code I have gotten away with currently:

%%% DOCUMENT %%%
\documentclass{beamer}
\usetheme{Antibes}
\usebeamercolor{dolphin}

%%% IMPORTS %%%
\usepackage{mathtools}
\usepackage{tikz}

%%% MAIN %%%
\begin{document}
\title{Stochastics and statistics -- Slides}
\section{Stochastic variables}
\subsection{Transformations}

\begin{frame}
    \frametitle{Example of linear transform}
    % Space pretending to be equations
    {\color{white}\begin{align*}
        f_X(x) &= \begin{dcases}
            e^{-x} \qquad &(x\geq 0)\\
            0 \qquad &(x<0)
        \end{dcases}\\
        &\Bigg\downarrow\qquad Y = 2X + 1 \quad\Leftrightarrow\quad X = \frac{Y-1}{2}\\
        f_Y(y) &= \begin{dcases}
            \frac{1}{2} e^{-\frac{y-1}{2}} \qquad &(y\geq 1)\\
            0 \qquad &(y < 1)
        \end{dcases}
    \end{align*}}
    \vspace{-1.5cm}
    % Figure and warning first
    \begin{columns}\hspace{0.5cm}
        \begin{column}{0.5\paperwidth}
            \begin{figure}
                \centering
                \includegraphics[width=\linewidth]{fig/graph}
            \end{figure}
        \end{column}
        \begin{column}{0.425\paperwidth}
            \begin{itemize}
                \item Warning: don't forget to transform the bounds!
            \end{itemize}
        \end{column}
    \end{columns}
    % Equations last, floating in a TikZ figure
    \begin{tikzpicture}[overlay,remember picture]
        \node[text width=10cm, anchor=south west] at (0.25cm,2.75cm) {
        \begin{align*}
            f_X(x) &= \begin{dcases}
                e^{-x} \qquad &(x\geq 0)\\
                0 \qquad &(x<0)
            \end{dcases}\\
            &\Bigg\downarrow\qquad Y = 2X + 1 \quad\Leftrightarrow\quad X = \frac{Y-1}{2}\\
            f_Y(y) &= \begin{dcases}
                \frac{1}{2} e^{-\frac{y-1}{2}} \qquad &(y\geq 1)\\
                0 \qquad &(y < 1)
            \end{dcases}
        \end{align*}
        };
    \end{tikzpicture}
\end{frame}

\end{document}

Good order but sucky code

Do not mind the quality of the graph please (we are refurbishing old PowerPoint slides).

3 Answers 3

1

Use \only<>{...}, \uncover<>{...} as needed. Just make sure the overlapping stuff doesn't end up printed at the same time. Be extra careful when generating presentations and handouts, use \mode<handout>{...}/mode<beamer>{...} to avoid handouts with overprints.

1
  • 1
    Could you show this applied to my example? This is not a question about animation.
    – Mew
    Commented Aug 22, 2021 at 19:23
0

Instead of worrying about the z-index of your frame, you could use some image manipulation tool like gimp and remove the white background. In Gimp, you can do that with the option "Color to Alpha...":

enter image description here

This results in

enter image description here


Alternatively you could make use of one of the beamer layers behind the main slide content:

%%% DOCUMENT %%%
\documentclass{beamer}
\usetheme{Antibes}
\usebeamercolor{dolphin}

%%% IMPORTS %%%
\usepackage{mathtools}
\usepackage{tikz}

%%% MAIN %%%
\begin{document}
\title{Stochastics and statistics -- Slides}
\section{Stochastic variables}
\subsection{Transformations}

{
\setbeamertemplate{background canvas}{
  \hspace{1cm}\rule{0pt}{.98\paperheight}%
  \includegraphics[width=.5\textwidth]{example-image-duck}
}
\begin{frame}[t]
    \frametitle{Example of linear transform}
    % Equations
    \begin{align*}
        f_X(x) &= \begin{dcases}
            e^{-x} \qquad &(x\geq 0)\\
            0 \qquad &(x<0)
        \end{dcases}\\
        &\Bigg\downarrow\qquad Y = 2X + 1 \quad\Leftrightarrow\quad X = \frac{Y-1}{2}\\
        f_Y(y) &= \begin{dcases}
            \frac{1}{2} e^{-\frac{y-1}{2}} \qquad &(y\geq 1)\\
            0 \qquad &(y < 1)
        \end{dcases}
    \end{align*}    
    \vspace{-1.5cm}
    % Figure and warning    
    \begin{columns}\hspace{0.5cm}
        \begin{column}{0.5\paperwidth}


        \end{column}
        \begin{column}{0.425\paperwidth}
            \begin{itemize}
                \item Warning: don't forget to transform the bounds!
            \end{itemize}
        \end{column}
    \end{columns}
\end{frame}
}

\end{document}

enter image description here

An overview of the available layers can be found in the beamer user guide, figure 1:

enter image description here

1
  • 1
    The Gimp solution is off-topic, so I won't engage it. The layers are interesting: is it possible to create a \zindex{idx}{ ... } command that accepts indices 1 to 11 and renders its second argument at that layer?
    – Mew
    Commented Sep 16, 2022 at 23:57
0

I also have been looking for an answer. I know these solutions are a bit unsatisfactory because they either add only a single background layer or they utilize the tikz library, which isn't exactly meant to control slides unless you interpret a slide as an image, then it's the perfect tool for formatting slides. These are examples and explanations of both methods

  1. You can put any content that you want in the background, which serves as a z = -1 layer.
\setbeamertemplate{background}
{
    \thepage
}
  1. You can create a tikz picture with layers. Tikz nodes can contain any latex content as far as I am aware. Nodes can be placed on different layers credit to this answer.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Preamble setup for tikz layers
\pgfdeclarelayer{back}
\pgfdeclarelayer{front}
\pgfsetlayers{back,main,front}

\makeatletter
\pgfkeys{%
  /tikz/on layer/.code={
    \pgfonlayer{#1}\begingroup
    \aftergroup\endpgfonlayer
    \aftergroup\endgroup
  },
  /tikz/node on layer/.code={
    \gdef\node@@on@layer{%
      \setbox\tikz@tempbox=\hbox\bgroup\pgfonlayer{#1}\unhbox\tikz@tempbox\endpgfonlayer\egroup}
    \aftergroup\node@on@layer
  },
  /tikz/end node on layer/.code={
    \endpgfonlayer\endgroup\endgroup
  }
}

\def\node@on@layer{\aftergroup\node@@on@layer}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% making a tikzpicture background that includes two nodes on separate layers and a table in one of the nodes
\setbeamertemplate{background}
{
    \begin{tikzpicture}
        \node[on layer=back] {lots of text for demonstration purposes just lots and lots of text and some more text here};
        \node[on layer=front, text=red] {%
            \begin{tabular*}{20cm}{|c|c|}
                \hline
                hopefully this text overlaps & with the other text \\
                and demonstrates that the red & text is on a layer in \\ \hline
                front of the other & text.
            \end{tabular*}
        };
    \end{tikzpicture} 
}

You must log in to answer this question.

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