如何在 Beamer 中逐帧显示图表中的图像

如何在 Beamer 中逐帧显示图表中的图像

我写了以下 tikz 代码

\documentclass[10pt]{beamer}
\usetheme{Warsaw}
\usetikzlibrary{calc, shapes, snakes, decorations.markings, patterns, , arrows.meta}
\usetikzlibrary{backgrounds} % For testing with "framed" option to look at the bounding box
\newcommand{\smallbead}[1]{\draw[fill] #1 circle [radius=0.1em]}

\begin{document}
\begin{frame}
\begin{figure}[H]
    %\label{}
    \centering
    \begin{tikzpicture}[
    single arrow/.style = {decoration={markings, mark=at position 0.5 with {\arrow{>}}}, postaction={decorate}},
    double arrow/.style = {decoration={markings, mark=at position 0.5 with {\arrow{>>}}}, postaction={decorate}},
    hatched/.style = {pattern=north west lines, opacity=0.3},
    ]
\begin{scope}[xshift=2cm]
        \coordinate (F1) at (-1, 2);
        \coordinate (F2) at (1, 2);
        \coordinate (E1) at (-2, 1);
        \coordinate (E3) at (0, 1);
        \coordinate (E2) at (2, 1);
        \coordinate (V) at (0, 0);

        \node [circle, above left] at (F1) {$f_1$};
        \node [above right] at (F2) {$f_2$};
        \node [left] at (E1) {$e_1$};
        \node [right] at (E2) {$e_2$};
        \node [above] at (E3) {$e_3$};
        \node [below] at (V) {$v$};

        \smallbead{(F1)};
        \smallbead{(F2)};
        \smallbead{(E1)};
        \smallbead{(E2)};
        \smallbead{(E3)};
        \smallbead{(V)};
        \draw [single arrow] (V) [bend left] to (E1);
        \draw [single arrow] (V) [bend right] to (E1);
        \draw [single arrow] (V) [bend left] to (E3);
        \draw [single arrow] (V) [bend right] to (E3);
        \draw [single arrow] (V) [bend left] to (E2);
        \draw [single arrow] (V) [bend right] to (E2);
        \draw [single arrow] (E1) to (F1);
        \draw [single arrow] (E1) to (F2);
        \draw [single arrow] (E2) to (F1);
        \draw [single arrow] (E2) to (F2);
\end{scope}
\end{tikzpicture}
\end{frame}
\end{document}

生成下图
enter image description here

我想在演示时使用此图表。

为了更好地展示,我不想在单个框架中显示图表,而是在 3 个不同的框架中显示。

第一帧应该只显示点和它们的标签。

第二个框架应该显示第一个框架的内容以及从最低级到中间级的箭头。

第三框用来显示整个图表。

当然,我可以通过编写 3 个不同的代码(每个帧一个)来实现这一点。但是有没有更聪明的方法呢?

编辑:我已经使用用户定义的命令\smallbead将点放在我想要的位置。

答案1

@Faekynn 解决方案适合您的示例

\documentclass{beamer}

\usepackage{tikz}

\begin{document}

\frame{\frametitle{unnumbered lists}
\begin{tikzpicture}[xshift=2cm]
\only<1-3>{
        \coordinate (F1) at (-1, 2);
        \coordinate (F2) at (1, 2);
        \coordinate (E1) at (-2, 1);
        \coordinate (E3) at (0, 1);
        \coordinate (E2) at (2, 1);
        \coordinate (V) at (0, 0);
        }
\only<2-3>{
        \node [circle, above left] at (F1) {$f_1$};
        \node [above right] at (F2) {$f_2$};
        \node [left] at (E1) {$e_1$};
        \node [right] at (E2) {$e_2$};
        \node [above] at (E3) {$e_3$};
        \node [below] at (V) {$v$};
} 
\only<3>{
        \draw [->] (V) [bend left] to (E1);
        \draw [->] (V) [bend right] to (E1);
        \draw [->] (V) [bend left] to (E3);
        \draw [->] (V) [bend right] to (E3);
        \draw [->] (V) [bend left] to (E2);
        \draw [->] (V) [bend right] to (E2);
        \draw [->] (E1) to (F1);
        \draw [->] (E1) to (F2);
        \draw [->] (E2) to (F1);
        \draw [->] (E2) to (F2);
        }

\end{tikzpicture}

}

\end{document}

答案2

您可以使用\only命令仅显示一帧中的部分幻灯片中的部分内容。这适用于所有内容,而不仅限于 tikz-pictures。

我还稍微清理了一下代码,使其仅包含与图片相关的内容......

\documentclass[]{beamer}
\usepackage{tikz}
\usetikzlibrary{decorations.markings, arrows.meta}
\newcommand{\smallbead}[1]{\draw[fill] #1 circle [radius=0.1em]}

\begin{document}
\begin{frame}
    \begin{tikzpicture}[ single arrow/.style = {decoration={markings, mark=at position 0.5 with {\arrow{>}}}, postaction={decorate}},  ]
        \coordinate (F1) at (-1, 2);
        \coordinate (F2) at (1, 2);
        \coordinate (E1) at (-2, 1);
        \coordinate (E3) at (0, 1);
        \coordinate (E2) at (2, 1);
        \coordinate (V) at (0, 0);

        \node [circle, above left] at (F1) {$f_1$};
        \node [above right] at (F2) {$f_2$};
        \node [left] at (E1) {$e_1$};
        \node [right] at (E2) {$e_2$};
        \node [above] at (E3) {$e_3$};
        \node [below] at (V) {$v$};

        \smallbead{(F1)};
        \smallbead{(F2)};
        \smallbead{(E1)};
        \smallbead{(E2)};
        \smallbead{(E3)};
        \smallbead{(V)};

        \only<2->{  % show this content only from the second slide onwards
        \draw [single arrow] (V) [bend left] to (E1);
        \draw [single arrow] (V) [bend right] to (E1);
        \draw [single arrow] (V) [bend left] to (E3);
        \draw [single arrow] (V) [bend right] to (E3);
        \draw [single arrow] (V) [bend left] to (E2);
        \draw [single arrow] (V) [bend right] to (E2);
        }
        \only<3>{ % only on third slide
        \draw [single arrow] (E1) to (F1);
        \draw [single arrow] (E1) to (F2);
        \draw [single arrow] (E2) to (F1);
        \draw [single arrow] (E2) to (F2);
       }
\end{tikzpicture}
\end{frame}
\end{document}

相关内容