这个问题导致了一个新的方案的出现:
aobs-tikz
是否可以更改以下 MWE 中的代码,使得“ABCD”在两张幻灯片上都可见,但只有在第二张幻灯片上才以红色节点作为背景?
\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}
使用类似的代码,我还希望有项目化,使得所有幻灯片上的所有项目都可见,但它们会以与前一个 MWE 中的“ABCD”相同的方式依次突出显示。(这与标准模式的不同之处
alert
在于,每次所有项目都可见,而不是更改项目的颜色,而是使用红色背景框。)
答案1
作为Andrew Stacey 指出 beamer
提供了一个自己的功能\newcommand<>
,可以更好地处理覆盖规范。
现在可以使用\tikzMe{BCD}<+>
。
由于 overlay-specification 参数内置了分隔符,因此需要对样式进行更改beameralert
。我选择了两个版本;这些样式是等效的:
beameralert=2
BeamerAlert=<2>
代码
\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}
输出
第 1 帧
第 2 帧
覆盖规范,
(例如<3,5>
)
经过小幅修改,使用逗号覆盖规范即可工作:
- 对呼叫本身进行分组
BeamerAlert
:BeamerAlert={#2}
分组
BeamerAlert
的alt
调用:BeamerAlert/.style={alt={#1{fill=red!30,rounded corners}{}},anchor=base}
代码
\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}
答案2
对于 s 的粉丝来说tikzstyle
,这里有一些样式可能有助于使元素可见draw
,fill
并shade
提供覆盖规范。
代码:
\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}
结果:
应用于 itemize 环境:
\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}
给出: