
我正在嘗試使用 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
用於此類用途。