以下代码在 Beamer 框架中逐级揭示森林树。但是,阴影会同时出现,而不是与节点一起出现。我该如何调整代码,使阴影与投射阴影的节点保持一致?
\documentclass{beamer}
\usepackage{forest}
\tikzset{% set up for transitions using tikz with beamer overlays - developed by Daniel (http://tex.stackexchange.com/a/55849/) and, in earlier form, by Matthew Leingang (http://tex.stackexchange.com/a/6155/) and modified for this use, I think by Qrrbrbirlbel (http://tex.stackexchange.com/a/112471/)
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}} % \pgfkeysalso doesn't change the path
},
}
\forestset{%
visible with edge from/.style={% based on visible on, developed by Qrrbrbirlbel (http://tex.stackexchange.com/a/112471/)
/tikz/visible on=<#1->,
/tikz/every label/.append style={visible on=<#1->},
edge={/tikz/visible on=<#1->},
},
}
\usetikzlibrary{shadows}
\begin{document}
\begin{frame}
\begin{forest}
for tree={
draw,
fill=white,
drop shadow,
},
before typesetting nodes={
for tree={
tempcounta/.option=level,
tempcounta'+=1,
visible with edge from/.register=tempcounta,
}
}
[first slide
[second slide[third slide][third slide]]
[second slide]
]
\end{forest}
\end{frame}
\end{document}
问题如下:
我以为我见过这个代码,但我似乎找不到重复的代码。特别是,我希望至少我以前没有问过这个问题!
答案1
不妨这样:我们不再处理\beamer@slideinframe
,而是追踪对象的不透明度,并将该不透明度应用于其阴影。如下所示
\def\tikzshadowopacityregister{1}
\tikzset{
invisible/.append code={\def\tikzshadowopacityregister{0}},
every shadow/.style={opacity=\tikzshadowopacityregister}
}
(将此放在后面,\usetikzlibrary{shadows}
否则every shadow
将被删除。)
这种策略在以下方面更加灵活:即使有一天有人想出了一些\setbeamercovered
以复杂的方式设置不透明度的方法,我们只需要通过全局宏走私结果并将其应用于阴影。
附言
我上面的方法与@Dr. Manuel Kuehner 非常相似。为了避免抄袭丑闻,这里有一个更灵活的版本
\makeatletter
\def\tikzopacityregister{1}
\tikzset{
opacity/.append code={
\pgfmathsetmacro\tikzopacityregister{#1*\tikzopacityregister}
},
opacity aux/.code={ % this is the original definition of opacity
\tikz@addoption{\pgfsetstrokeopacity{#1}\pgfsetfillopacity{#1}}
},
every shadow/.style={opacity aux=\tikzopacityregister}
}
答案2
这是评论以某种我不太理解的方式向我暗示的。也就是说,它实际上似乎与评论中的建议无关,我不理解并且无法使之发挥作用。但我在尝试使其发挥作用后立即想到了这一点,这表明存在着不平凡的联系。
我不喜欢这个解决方案,因为它需要为每个 drop-shadow-like-item 创建额外的样式,然后将其与主覆盖规范分开应用。这很容易出错,而我却很擅长处理错误。
然而,严格来说,它确实回答了我提出的具体问题,所以也许它会启发某人提供更令人满意的方法。
\documentclass{beamer}
\usepackage{forest}
\tikzset{% set up for transitions using tikz with beamer overlays - developed by Daniel (http://tex.stackexchange.com/a/55849/) and, in earlier form, by Matthew Leingang (http://tex.stackexchange.com/a/6155/) and modified for this use, I think by Qrrbrbirlbel (http://tex.stackexchange.com/a/112471/)
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}} % \pgfkeysalso doesn't change the path
},
}
\forestset{%
visible with edge from/.style={% based on visible on, developed by Qrrbrbirlbel (http://tex.stackexchange.com/a/112471/)
/tikz/visible on=<#1->,
/tikz/every label/.append style={visible on=<#1->},
edge={/tikz/visible on=<#1->},
},
drop shadow visible from/.style={/tikz/alt=<#1->{drop shadow}{}},
}
\usetikzlibrary{shadows}
\begin{document}
\begin{frame}
\begin{forest}
for tree={
draw,
fill=white,
},
before typesetting nodes={
for tree={
tempcounta/.option=level,
tempcounta'+=1,
visible with edge from/.register=tempcounta,
drop shadow visible from/.register=tempcounta,
}
}
[first slide
[second slide[third slide][third slide]]
[second slide]
]
\end{forest}
\end{frame}
\end{document}