[Tex/LaTex] Highlighting in Beamer using TikZ nodes

beamerhighlightingoverlayspresentationstikz-pgf

This question led to a new package:
aobs-tikz

  1. Is it possible to alter the code in the following MWE to the effect that “ABCD” is visible on both slides but only on the second it has the red node as background?

    \documentclass{beamer}
    \usepackage{tikz}
    \tikzset{
        invisible/.style={opacity=0,text opacity=0},
        visible on/.style={alt=#1{}{invisible}},
        alt/.code args={<#1>#2#3}{%
          \alt<#1>{\pgfkeysalso{#2}}{\pgfkeysalso{#3}} 
        },
      }
    \begin{document}
    \frame{\frametitle{Title}
    \tikz[remember picture,baseline=(A.base)] \node[fill=red!30,anchor=base,rounded corners,visible on=<2>] (A) {ABCD};
    }
    \end{document}
    
  2. Using similar code, I would also like to have itemizations such that on all slides all items are visible but they are successively highlighted in the same way as the “ABCD” in the previous MWE. (This differs from the standard alert mode in that at every time all items are visible and instead of changing the color of the item one uses a red background box.)

Best Answer

As Andrew Stacey pointed out beamer provides an own \newcommand<> that deals a little better with overlay specification.
It is now possible to use \tikzMe{BCD}<+>.

As the overlay-specification argument has the delimiters built-in, so changes need to be made to the beameralert style. I opted for two versions; these styles are equivalent:

  • beameralert=2
  • BeamerAlert=<2>

Code

\documentclass[t]{beamer}
\usepackage{tikz}
\tikzset{
    invisible/.style={opacity=0,text opacity=0},
    visible on/.style={alt=#1{}{invisible}},
    alt/.code args={<#1>#2#3}{%
      \alt<#1>{\pgfkeysalso{#2}}{\pgfkeysalso{#3}} 
    },
    beameralert/.style={alt=<#1>{fill=red!30,rounded corners}{},anchor=base},
    BeamerAlert/.style={alt=#1{fill=red!30,rounded corners}{},anchor=base}
}
  \newcommand<>{\tikzMe}[1]{% previously: \def\tikzMe<#1>#2{…
    \tikz[baseline]\node[BeamerAlert=#2,anchor=base] {#1};
}
\begin{document}
\begin{frame}{One node}
    \tikz[baseline]\node[beameralert=2,anchor=base] {ABCD};
\end{frame}
\begin{frame}{Itemizing (Ti\emph{k}Z)}
    \begin{itemize}
        \item \tikzMe<+>{ABC}
        \item \tikzMe{BCD}<+>% (this works thanks to \newcommand<>)
        \item \tikzMe<+>{CDE}
    \end{itemize}
\end{frame}
\end{document}

Output

Frame 1

enter image description here enter image description here

Frame 2

enter image description here enter image description here enter image description here

Overlay specifications with , (e.g. <3,5>)

With a small modification overlay specifications with a comma do work:

  • Grouping the BeamerAlert call itself: BeamerAlert={#2}
  • grouping BeamerAlert's alt call:

    BeamerAlert/.style={alt={#1{fill=red!30,rounded corners}{}},anchor=base}
    

Code

\documentclass[t]{beamer}
\usepackage{tikz}
\tikzset{
    invisible/.style={opacity=0,text opacity=0},
    visible on/.style={alt=#1{}{invisible}},
    alt/.code args={<#1>#2#3}{%
      \alt<#1>{\pgfkeysalso{#2}}{\pgfkeysalso{#3}} 
    },
    beameralert/.style={alt={<#1>{fill=red!30,rounded corners}{}},anchor=base},
    BeamerAlert/.style={alt={#1{fill=red!30,rounded corners}{}},anchor=base}
}
  \newcommand<>{\tikzMe}[1]{% previously: \def\tikzMe<#1>#2{…
    \tikz[baseline]\node[BeamerAlert={#2},anchor=base] {#1};
}
\begin{document}
\begin{frame}{One node}
    \tikz[baseline]\node[beameralert=2,anchor=base] {ABCD};
\end{frame}
\begin{frame}{Itemizing (Ti\emph{k}Z)}
    \begin{itemize}
        \item \tikzMe<+>{ABC}
        \item \tikzMe{BCD}<3,5>% (this works thanks to \newcommand<>)
        \item \tikzMe<+>{CDE}
    \end{itemize}
\end{frame}
\end{document}