我正在尝试使用 onslide 将不同的图片元素组合在一起,并控制它们在幻灯片上出现的时间和时间。同时,我正在尝试使用 pgfonlayer 确保某些东西被绘制在其他东西的“下方”,以确保正确的遮挡。
我认为它们应该完全独立,但我发现当我将元素放入 pgfonlayer 环境(位于 onslide 内部)时,它似乎将同一 pgf 背景层中的所有项目放入与 onslide<1-> 等效的内容中。几乎就像 pgfonlayer 取消了 onslide 的效果一样。
更准确地说,我可以得到类似这样的结果(这是问题的草图——A、B、C、D 是真实的图形,而不仅仅是字母):
\onslide<1>{
B
\begin{pgfonlayer}{bg}
A % A should be occluded by B
\end{pgfonlayer}
}
\onslide<2>{
D
\begin{pgfonlayer}{bg}
C % C should be occluded by D
\end{pgfonlayer}
}
并且我得到的效果是 A 和 C 始终可见。
有没有简单的方法可以解决这个问题?任何帮助都将不胜感激。
谢谢,
安布罗斯
附言:以下是完整的源代码示例:
\documentclass[10pt]{beamer}
\title{onslide vs pgfonlayer}
\author[My Team]{My Name}
\date{\today}
\usepackage{tikz}
\begin{document}
\begin{frame}[t]
\frametitle{First using pgfonlayer only -- works.}
On this first slide the light colors are on top, even though they are
drawn before the darker colors. {\bf pgfonlayer} is used to achieve
this.
\pgfdeclarelayer{bg}
\pgfsetlayers{bg,main}
\begin{figure}
\begin{tikzpicture}
\draw[fill=blue!10] (0,1) circle (1cm);
\begin{pgfonlayer}{bg}
\draw[fill=blue] (0,0) circle (1cm);
\end{pgfonlayer}
\draw[fill=red!10] (3,1) circle (1cm);
\begin{pgfonlayer}{bg}
\draw[fill=red] (3,0) circle (1cm);
\end{pgfonlayer}
\end{tikzpicture}
\end{figure}
\end{frame}
\begin{frame}[t]
\frametitle{Next, adding onslide -- fails.}
On this second slide I attempt to use {\bf onslide} to show only one
side at a time. First the blues then the reds.
\pgfdeclarelayer{bg}
\pgfsetlayers{bg,main}
\begin{figure}
\begin{tikzpicture}
\onslide<1>{
\draw[fill=blue!10] (0,1) circle (1cm);
\begin{pgfonlayer}{bg}
\draw[fill=blue] (0,0) circle (1cm);
\end{pgfonlayer}
}
\onslide<2>{
\draw[fill=red!10] (3,1) circle (1cm);
\begin{pgfonlayer}{bg}
\draw[fill=red] (3,0) circle (1cm);
\end{pgfonlayer}
}
\end{tikzpicture}
\end{figure}
First we see light blue with both dark colors, ...\pause and then we
see light red with both dark colors. It seems that because I put the
darker colors into the bg layer, the onslide groupings I put around
each basic color do not work
\end{frame}
\end{document}
答案1
你是对的:pgfonlayer
环境取消了的效果\onslide
!
解决方法:
\documentclass[10pt]{beamer}
\usepackage{tikz}
\begin{document}
\begin{frame}[t]
\frametitle{pgfonlayer and onslide...}
\pgfdeclarelayer{bg}
\pgfsetlayers{bg,main}
\begin{figure}
\begin{tikzpicture}
\onslide<1>{
\draw[fill=blue!10] (0,1) circle (1cm);
\begin{pgfonlayer}{bg}
\onslide<1>{
\draw[fill=blue] (0,0) circle (1cm);
}
\end{pgfonlayer}
}
\onslide<2>{
\draw[fill=red!10] (3,1) circle (1cm);
\begin{pgfonlayer}{bg}
\onslide<2>{
\draw[fill=red] (3,0) circle (1cm);
}
\end{pgfonlayer}
}
\end{tikzpicture}
\end{figure}
\end{frame}
\end{document}
答案2
我认为这是 TikZ 和 沟通不畅的情况之一。最简单的解决方案是向图层上的命令beamer
添加特定的叠加规范,这使得叠加规范成为一个(如果我没记错的话)。因此,它故意指示删除幻灯片上发生的事情,而不像。draw
background
\only
\onslide
我强烈建议使用backgrounds
专为此任务量身定制的 TikZ 库。我不知道它到底能做什么,但如果我们感兴趣的只是背景,最好让 TikZ 进行分层。
\documentclass[10pt]{beamer}
\title{onslide vs pgfonlayer}
\author[My Team]{My Name}
\date{\today}
\usepackage{tikz}
\usetikzlibrary{backgrounds}
\begin{document}
\begin{frame}[t]{First using pgfonlayer only -- works.}
On this first slide the light colors are on top, even though they are
drawn before the darker colors. \textbf{pgfonlayer} is used to achieve
this.
\begin{figure}
\begin{tikzpicture}
\draw[fill=blue!10] (0,1) circle (1cm);
\begin{scope}[on background layer]
\draw[fill=blue] (0,0) circle (1cm);
\end{scope}
\draw[fill=red!10] (3,1) circle (1cm);
\begin{scope}[on background layer]
\draw[fill=red] (3,0) circle (1cm);
\end{scope}
\end{tikzpicture}
\end{figure}
\end{frame}
\begin{frame}[t]{Next, adding onslide -- fails.}
On this second slide the light colors are on top, even though they are
drawn before the darker colors. \textbf{pgfonlayer} is used to achieve
this.
\begin{figure}
\begin{tikzpicture}
\onslide<1>{
\draw[fill=blue!10] (0,1) circle (1cm);
\begin{scope}[on background layer]
\draw<1>[fill=blue] (0,0) circle (1cm);
\end{scope}
}
\onslide<2>{
\draw[fill=red!10] (3,1) circle (1cm);
\begin{scope}[on background layer]
\draw<2>[fill=red] (3,0) circle (1cm);
\end{scope}
}
\end{tikzpicture}
\end{figure}
First \pause and second
\end{frame}
\end{document}
一个小细节:\bf
已被弃用,仅用于\textbf
此类用途。