Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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.)

share|improve this question
    
1. \node[alt=<2>{fill=red!30,rounded corners}{},anchor=base] (A) {ABCD}; 2. Are you thinking of something like \foreach \i in {1,...,4} \tikz[remember picture,baseline] \node[alt=<\i>{fill=red!30,rounded corners}{},anchor=base] (A) {ABCD};? In the last example <\i> can be substituted by <+>. –  Qrrbrbirlbel Nov 27 '12 at 18:10
    
1. That works fine, thanks! 2. I am thinking of \begin{itemize}\item abc\item cde\item fgh\item ijk\end{itemize} such that on all slides all items are visible but item i is highlighted by a node as before on slide i only. Not sure whether that's what you had in mind ...(?) –  lpdbw Nov 27 '12 at 19:13
    
Ah, I am stupid. 2) can be solved exactly in the same way as 1)! So please write your comment into an asnwer so that I can accept it. Thanks. –  lpdbw Nov 27 '12 at 19:18

2 Answers 2

up vote 16 down vote accepted

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}
share|improve this answer
    
Great solution, thanks! And so much better than the standard beamer itemize alert solution! –  lpdbw Nov 27 '12 at 19:40
1  
I like the macro name: \tikzMe! –  Loop Space Nov 27 '12 at 21:44
1  
Looking closely at the definition of \tikzMe, I see that it takes an overlay specification. There is a "proper" mechanism in beamer for defining such commands which also makes them optional: \newcommand<>{\tikzMe}[1]{...}. To ensure that \tikzMe behaved "as expected" I recommend using this "proper" method. –  Loop Space Nov 27 '12 at 21:56
    
@AndrewStacey Sure, thanks! I didn't even know that \overlayAware{arg1}<overlaySpec>{arg2} was possible … –  Qrrbrbirlbel Nov 27 '12 at 22:19
1  
@lpdbw Yes, see my updated answer. –  Qrrbrbirlbel Dec 2 '12 at 15:25

For fans of tikzstyles, here are a bunch of styles that might help in made visible elements as draw, fill and shade upon providing overlay specifications.

The code:

\documentclass{beamer}
\usepackage{lmodern}
\usepackage{tikz}
\usetikzlibrary{shapes.geometric}

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

\tikzset{
  background fill/.style={fill=#1},
  background fill/.default={white},
  fill on/.style={alt=#1{}{background fill}},
}

\tikzset{
  background draw/.style={draw=#1},
  background draw/.default={white},
  draw on/.style={alt=#1{}{background draw}},
}

\tikzset{
  background filldraw/.style 2 args={draw=#1, fill=#2},
  background filldraw/.default={white}{white},
  filldraw on/.style={alt=#1{}{background filldraw}},
}

\tikzset{
  background shade/.style={#1},
  background shade/.default={top color=white, bottom color=white},
  shade on/.style={alt=#1{}{background shade}},
}

\tikzset{
  background shadedraw/.style 2 args={draw=#1, #2},
  background shadedraw/.default={white}{top color=white, bottom color=white},
  shadedraw on/.style={alt=#1{}{background shadedraw}},
}

\begin{document}
\begin{frame}{Title}
\begin{columns}[T]
\begin{column}{0.2\textwidth}
\centering
Fill draw\\[2ex]
\tikz[baseline=(A.base)] \node[background fill=red!50,fill on=<2>,anchor=base,rounded corners,visible on=<1->] (A) {ABCD};

\tikz[baseline=(A.base)] \node[background fill=blue!50,fill on=<{1,3}>,anchor=base,rounded corners,visible on=<1->] (A) {EFGH};

\tikz[baseline=(A.base)] \node[background draw=red,draw on=<2>,anchor=base,rounded corners,visible on=<1->] (A) {IJKL};

\tikz[baseline=(A.base)] \node[background draw=blue,draw on=<{1,3}>,anchor=base,rounded corners,visible on=<1->] (A) {MNOP};

\tikz[baseline=(A.base)] \node[background filldraw={red}{blue!10},filldraw on=<2>,anchor=base,rounded corners,visible on=<1->] (A) {QRST};
\end{column}
\begin{column}{0.2\textwidth}
\centering
Shadings\\[2ex]
\tikz[baseline=(A.base)] \node[background shade={top color=red!50, bottom color=white},shade on=<2>,anchor=base,rounded corners,visible on=<1->] (A) {ABCD};

\tikz[baseline=(A.base)] \node[background shade={inner color=red!50, outer color=white},shade on=<{1,3}>,anchor=base,rounded corners,visible on=<1->] (A) {EFGH};

\tikz[baseline=(A.base)] \node[background shade={left color=orange!50, right color=white},shade on=<2>,anchor=base,rounded corners,visible on=<1->] (A) {IJKL};

\tikz[baseline=(A.base)] \node[background shadedraw={blue}{top color=white, bottom color=cyan!30},shadedraw on=<{1,3}>,anchor=base,rounded corners,visible on=<1->] (A) {MNOP};

\tikz[baseline=(A.base)] \node[background shadedraw={green!50!black}{inner color=white, outer color=green!30},shadedraw on=<2>,anchor=base,rounded corners,visible on=<1->] (A) {QRST};
\end{column}
\begin{column}{0.55\textwidth}
\centering
Node application\\[2ex]
\begin{tikzpicture}
\tikzset{visibility 1/.style={background draw=red, draw on=<{1,4}>,     
        background shade={top color=white,bottom color=red!30}, shade on=<{2,3}>,
    }
}
\tikzset{visibility 2/.style={  
        background shadedraw={green!50!black}{inner color=white,outer color=green!30}, shadedraw on=<{2,3}>,
    }
}
\tikzset{visibility 3/.style={  background draw=orange, draw on=<1->,       
        background fill={orange!30}, fill on=<{2,3}>,
    }
}
\tikzset{visibility 4/.style={  background draw=purple, draw on=<2->,       
        background shade={left color=purple!30, right color=cyan!30}, shade on=<{3,4}>,
    }
}
\node[visible on=<1->,trapezium,visibility 1] (A) {Text};
\node[visible on=<1->,trapezium,visibility 2, below of=A] (B) {Text};
\node[visible on=<1->,trapezium,visibility 3, below of=B] (C) {Text};
\node[visible on=<1->,trapezium,visibility 4, below of=C] (D) {Text};
\end{tikzpicture}
\end{column}
\end{columns}
\end{frame}
\end{document}

The result:

enter image description here

Applied to the itemize environment:

\documentclass{beamer}
\usepackage{lmodern}
\usepackage{tikz}
\usetikzlibrary{shapes.geometric}

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

\tikzset{
  background fill/.style={fill=#1},
  background fill/.default={white},
  fill on/.style={alt=#1{}{background fill}},
}

\tikzset{
  background draw/.style={draw=#1},
  background draw/.default={white},
  draw on/.style={alt=#1{}{background draw}},
}

\tikzset{
  background filldraw/.style 2 args={draw=#1, fill=#2},
  background filldraw/.default={white}{white},
  filldraw on/.style={alt=#1{}{background filldraw}},
}

\tikzset{
  background shade/.style={#1},
  background shade/.default={top color=white, bottom color=white},
  shade on/.style={alt=#1{}{background shade}},
}

\tikzset{
  background shadedraw/.style 2 args={draw=#1, #2},
  background shadedraw/.default={white}{top color=white, bottom color=white},
  shadedraw on/.style={alt=#1{}{background shadedraw}},
}

% Command for sequentially fill the items
\newcommand{\itemfill}[1]{\tikz[baseline=(A.base)] \node[background fill=red!30,fill on=<+>,anchor=base,rounded corners,visible on=<1->] (A) {#1};}

\begin{document}

\begin{frame}{Itemize with styles}
\begin{itemize}
\item \itemfill{ABC}
\item \itemfill{BCD}
\item \itemfill{CDE}
\end{itemize}
\end{frame}

\end{document}

gives:

enter image description here

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.