我认为我的问题非常简单,但我还没有找到合适的解决方案。
我想要一个 tikzpicture,它将在下一张幻灯片上被其他 tikz 内容覆盖。例如一个矩形,这样整个图片就可以透明,并在其上方添加一些文本。但是,我还没有找到任何解决方案,如何在同一张幻灯片上叠加 tikz 内容而不影响彼此的定位。我尝试使用前景
把它们放在不同的幻灯片上,定位是独立的:
\documentclass{beamer}
\usepackage{tikz}
\usetikzlibrary{positioning}
\pgfdeclarelayer{background}
\pgfdeclarelayer{foreground}
\pgfsetlayers{background,main,foreground}
\begin{document}
\begin{frame}[c]{Frame Titel}
\centering
\begin{tikzpicture}
\only<1>{
\node[circle,minimum width=4cm,fill=red](a){};
\node[left=-1cm of a.south west](SUST){Sustainability};
\node[yshift=2cm,xshift=2cm,circle,minimum width=4cm,fill=green](b){};
\node[right=-1cm of b.north east](PSY){Psychology};
\node[yshift=-1cm,xshift=3cm,circle,minimum width=4cm,fill=blue](c){};
\node[right=-1cm of c.south east](MARK){Marketing};
}
\only<2>
{
\begin{pgfonlayer}{foreground}
\centering
\node[rectangle,minimum width=\textwidth,minimum height=\textheight,fill=gray,opacity=0.8](node name){};
\end{pgfonlayer}{foreground}
}
\end{tikzpicture}
\end{frame}
\end{document}
但当将它们放在同一张幻灯片上时,背景部分会移动:
\documentclass{beamer}
\usepackage{tikz}
\usetikzlibrary{positioning}
\pgfdeclarelayer{background}
\pgfdeclarelayer{foreground}
\pgfsetlayers{background,main,foreground}
\begin{document}
\begin{frame}[c]{Frame Titel}
\centering
\begin{tikzpicture}
\only<1->{
\node[circle,minimum width=4cm,fill=red](a){};
\node[left=-1cm of a.south west](SUST){Sustainability};
\node[yshift=2cm,xshift=2cm,circle,minimum width=4cm,fill=green](b){};
\node[right=-1cm of b.north east](PSY){Psychology};
\node[yshift=-1cm,xshift=3cm,circle,minimum width=4cm,fill=blue](c){};
\node[right=-1cm of c.south east](MARK){Marketing};
}
\only<2>
{
\begin{pgfonlayer}{foreground}
\centering
\node[rectangle,minimum width=\textwidth,minimum height=\textheight,fill=gray,opacity=0.8](node name){};
\end{pgfonlayer}{foreground}
}
\end{tikzpicture}
\end{frame}
\end{document}
答案1
欢迎!有一个专门用于这种情况的库,overlay-beamer-styles
。它的工作原理是将幻灯片上应隐藏对象的不透明度设置为零。由于您想使用opacity=0.8
,您需要使用alt
键。您可以将矩形放置在(current bounding box.center)
以使其适当居中。所以你想使用
\node[rectangle,minimum width=\textwidth,minimum height=\textheight,
fill=gray,alt=<2->{opacity=0.8}{opacity=0}](node name) at (current
bounding box.center){};
请注意,这\centering
没有效果。此外,foreground
不需要该层,但我保留它,假设您想添加更多元素。我在以下示例中介绍了这两种情况。
\documentclass{beamer}
\usepackage{tikz}
\usetikzlibrary{positioning,overlay-beamer-styles}
\pgfdeclarelayer{background}
\pgfdeclarelayer{foreground}
\pgfsetlayers{background,main,foreground}
\begin{document}
\begin{frame}[c]{Only visible on $<1>$}
\centering
\begin{tikzpicture}
\begin{scope}[visible on=<1>]
\node(a){\includegraphics[width=4cm]{example-image-a.pdf}};
\node[left=-1cm of a.south west](SUST){Sustainability};
\node[yshift=2cm,xshift=2cm](b){\includegraphics[width=4cm]{example-image-b.pdf}};
\node[right=-1cm of b.north east](PSY){Psychology};
\node[yshift=-1cm,xshift=3cm](c){\includegraphics[width=4cm]{example-image-c}};
\node[right=-1cm of c.south east](MARK){Marketing};
\end{scope}
\begin{pgfonlayer}{foreground}
\node[rectangle,minimum width=\textwidth,minimum height=\textheight,
fill=gray,alt=<2->{opacity=0.8}{opacity=0}](node name) at (current
bounding box.center){};
\end{pgfonlayer}{foreground}
\end{tikzpicture}
\end{frame}
\begin{frame}[c]{Visible on $<1-2>$}
\centering
\begin{tikzpicture}
\begin{scope}[visible on=<1-2>]
\node(a){\includegraphics[width=4cm]{example-image-a.pdf}};
\node[left=-1cm of a.south west](SUST){Sustainability};
\node[yshift=2cm,xshift=2cm](b){\includegraphics[width=4cm]{example-image-b.pdf}};
\node[right=-1cm of b.north east](PSY){Psychology};
\node[yshift=-1cm,xshift=3cm](c){\includegraphics[width=4cm]{example-image-c}};
\node[right=-1cm of c.south east](MARK){Marketing};
\end{scope}
\begin{pgfonlayer}{foreground}
\centering
\node[rectangle,minimum width=\textwidth,minimum height=\textheight,
fill=gray,alt=<2->{opacity=0.8}{opacity=0}](node name) at (current
bounding box.center){};
\end{pgfonlayer}{foreground}
\end{tikzpicture}
\end{frame}
\end{document}
答案2
还可以使用overlay-beamer-styles
及其宏\alt{...}{...}
(正如@Schrödinger's cat 在他的回答中所建议的那样),但没有和,\only<...>
就像pgfonlayer
你在 MWE 中那样:
\documentclass{beamer}
\usepackage{tikz}
\usetikzlibrary{positioning,
overlay-beamer-styles}
\begin{document}
\begin{frame}
\frametitle{Frame Titel}
\centering
\setkeys{Gin}{width=4cm}
\begin{tikzpicture}[
inner sep = 0pt,
every label/.style = {label distance=-1mm, inner sep=2mm}
]
\node[label=below left:Sustainability] (a) {\includegraphics{example-image-duck}};
\node[label=above right:Psychology,
above right=8mm and 0mm of a.center] (b) {\includegraphics{example-image-duck}}; \node[label=below right:Marketing,
below right=3mm and 9mm of a.center] (c) {\includegraphics{example-image-duck}};
\fill[gray,
alt=<2->{fill opacity=0.8, text opacity=1}{fill opacity=0, text opacity=0}, % <---
scale=1.2]
(current bounding box.south west) rectangle
(current bounding box.north east)
node[midway, font=\huge, text=red] {some text};
\end{tikzpicture}
\end{frame}
\end{document}