如何使用 \onslide 之类的命令在不同的幻灯片上显示 tikz 和文本?

如何使用 \onslide 之类的命令在不同的幻灯片上显示 tikz 和文本?

我要解释一个过程的 5 个基本步骤,并决定使用 tikzpicture 来更好地解释它。我有这五张幻灯片,其中包含文本和 tikzpitures。

\documentclass{beamer}
\usepackage{blindtext}
\usetheme{Madrid}
\usepackage{tikz}
\usetikzlibrary{arrows.meta,
chains,
positioning, 
shadows.blur, shapes.arrows}

\begin{document}
\begin{frame}
\frametitle{~}
\begin{block}{~}
    My explanation for first box is put here.

    My explanation for first box is put here.

    My explanation for first box is put here.

    My explanation for first box is put here.

    My explanation for first box is put here.
\end{block}
    \begin{figure}[H]
    \begin{center}
    \begin{tikzpicture}[
    node distance = 2mm and 7mm,
    nodes = {draw, fill=white, blur shadow},
    arj/.style = {draw=gray, ultra thick,-Straight Barb},
    arr/.style = {single arrow, single arrow head extend=1mm,
        minimum height=9mm, shape border rotate=90,
        node contents={~}},
    box/.style = {text width=0.14\linewidth, align=center,inner sep=2pt,
        minimum height=12mm, font=\scriptsize,
        on chain, join = by  arj},
    ]
    \begin{scope}[start chain = A going right]
    \foreach \i [count=\j] in   {Problem Identification
    }
    {
        \node (m\j) [box] {\i};
    }
    \end{scope}

    \end{tikzpicture}
\end{center}
\caption{~}
\caption*{\textit{\textbf{Source:} Self Motivated}}
\end{figure}
\end{frame}

\begin{frame}
\frametitle{~}
\begin{block}{~}
    My explanation for the second box is put here.
    My explanation for the second box is put here.
    My explanation for the second box is put here.
    My explanation for the second box is put here.
    My explanation for the second box is put here.
    My explanation for the second box is put here.
\end{block}
\begin{figure}[H]
    \begin{center}
        \begin{tikzpicture}[
        node distance = 2mm and 7mm,
        nodes = {draw, fill=white, blur shadow},
        arj/.style = {draw=gray, ultra thick,-Straight Barb},
        arr/.style = {single arrow, single arrow head extend=1mm,
            minimum height=9mm, shape border rotate=90,
            node contents={~}},
        box/.style = {text width=0.14\linewidth, align=center,inner sep=2pt,
            minimum height=12mm, font=\scriptsize,
            on chain, join = by  arj},
        ]
        \begin{scope}[start chain = A going right]
        \foreach \i [count=\j] in   {
            Problem Identification, Statistics
        }
        {
            \node (m\j) [box] {\i};
        }
        \end{scope}
        %\draw[arj] (m3) -- (m2);
        \end{tikzpicture}
    \end{center}
    \caption{~}
    \caption*{\textit{\textbf{Source:} Self Motivated}}
\end{figure}
\end{frame}

\begin{frame}
\frametitle{~}
\begin{block}{~}
    My explanation for the third box is put here.
    My explanation for the third box is put here.
    My explanation for the third box is put here.
    My explanation for the third box is put here.
    My explanation for the third box is put here.
    My explanation for the third box is put here.
\end{block}
\begin{figure}[H]
    \begin{center}
        \begin{tikzpicture}[
        node distance = 2mm and 7mm,
        nodes = {draw, fill=white, blur shadow},
        arj/.style = {draw=gray, ultra thick,-Straight Barb},
        arr/.style = {single arrow, single arrow head extend=1mm,
            minimum height=9mm, shape border rotate=90,
            node contents={~}},
        box/.style = {text width=0.14\linewidth, align=center,inner sep=2pt,
            minimum height=12mm, font=\scriptsize,
            on chain, join = by  arj},
        ]
        \begin{scope}[start chain = A going right]
        \foreach \i [count=\j] in   {
            Problem Identification, Statistics, Planning
        }
        {
            \node (m\j) [box] {\i};
        }
        \end{scope}
        \draw[arj] (m3) -- (m2);
        \end{tikzpicture}
    \end{center}
    \caption{~}
    \caption*{\textit{\textbf{Source:} Self Motivated}}
\end{figure}
\end{frame}

\begin{frame}
\frametitle{~}
\begin{block}{~}
    My explanation for the fourth box is put here.
    My explanation for the fourth box is put here.
    My explanation for the fourth box is put here.
    My explanation for the fourth box is put here.
    My explanation for the fourth box is put here.
\end{block}
\begin{figure}[H]
    \begin{center}
        \begin{tikzpicture}[
        node distance = 2mm and 7mm,
        nodes = {draw, fill=white, blur shadow},
        arj/.style = {draw=gray, ultra thick,-Straight Barb},
        arr/.style = {single arrow, single arrow head extend=1mm,
            minimum height=9mm, shape border rotate=90,
            node contents={~}},
        box/.style = {text width=0.14\linewidth, align=center,inner sep=2pt,
            minimum height=12mm, font=\scriptsize,
            on chain, join = by  arj},
        ]
        \begin{scope}[start chain = A going right]
        \foreach \i [count=\j] in   {
            Problem Identification, Statistics, Planning,
            Imple\-men\-ta\-tion of Plans
        }
        {
            \node (m\j) [box] {\i};
        }
        \end{scope}
        \draw[arj] (m3) -- (m2);
        \end{tikzpicture}
    \end{center}
    \caption{~}
    \caption*{\textit{\textbf{Source:} Self Motivated}}
\end{figure}
\end{frame}

\begin{frame}
\frametitle{~}
\begin{block}{~}
    My explanation for the fifth box is put here.
    My explanation for the fifth box is put here.
    My explanation for the fifth box is put here.
    My explanation for the fifth box is put here.
    My explanation for the fifth box is put here.
    My explanation for the fifth box is put here.
    My explanation for the fifth box is put here.
\end{block}
\begin{figure}[H]
    \begin{center}
        \begin{tikzpicture}[
        node distance = 2mm and 7mm,
        nodes = {draw, fill=white, blur shadow},
        arj/.style = {draw=gray, ultra thick,-Straight Barb},
        arr/.style = {single arrow, single arrow head extend=1mm,
            minimum height=9mm, shape border rotate=90,
            node contents={~}},
        box/.style = {text width=0.14\linewidth, align=center,inner sep=2pt,
            minimum height=12mm, font=\scriptsize,
            on chain, join = by  arj},
        ]
        \begin{scope}[start chain = A going right]
        \foreach \i [count=\j] in   {
            Problem Identification, Statistics, Planning,
            Imple\-men\-ta\-tion of Plans, De\-ve\-lop\-ment
        }
        {
            \node (m\j) [box] {\i};
        }
        \end{scope}
        \draw[arj] (m3) -- (m2);
        \end{tikzpicture}
    \end{center}
    \caption{~}
    \caption*{\textit{\textbf{Source:} Self Motivated}}
\end{figure}
\end{frame}
\end{document}

我如何使用类似的命令\onslide来对其进行编程,以便我不需要写\begin{frame}...\end{frame}5 次,同时仍然可以获得相同甚至更好的结果?

答案1

由于您已经在循环\j内部定义了计数器\foreach,因此用 包围节点就足够了\only<\j->{...}。这会产生:

在此处输入图片描述

这是您修改后的代码:

\documentclass{beamer}
\usepackage{blindtext}
\usetheme{Madrid}
\usepackage{tikz}
\usetikzlibrary{arrows.meta,
chains,
positioning,
shadows.blur, shapes.arrows}

\begin{document}

\begin{frame}
\frametitle{~}
\begin{block}{~}
\blindtext.
\end{block}
\begin{figure}[H]
    \begin{center}
        \begin{tikzpicture}[
        node distance = 2mm and 7mm,
        nodes = {draw, fill=white, blur shadow},
        arj/.style = {draw=gray, ultra thick,-Straight Barb},
        arr/.style = {single arrow, single arrow head extend=1mm,
            minimum height=9mm, shape border rotate=90,
            node contents={~}},
        box/.style = {text width=0.14\linewidth, align=center,inner sep=2pt,
            minimum height=12mm, font=\scriptsize,
            on chain, join = by  arj},
        ]
        \begin{scope}[start chain = A going right]
        \foreach \txt [count=\j] in   {
            Problem Identification, Statistics, Planning,
            Imple\-men\-ta\-tion of Plans, De\-ve\-lop\-ment
        }
        {
            \only<\j->{\node (m\j) [box] {\txt};}
        }
        \end{scope}
        \end{tikzpicture}
    \end{center}
    \caption{~}
    \caption*{\textit{\textbf{Source:} Self Motivated}}
\end{figure}
\end{frame}
\end{document}

您还可以使用类似以下结构:\only<\j+1>{...}如果您想修改幻灯片出现的“时间”——或者更改计数器的初始值\j。最后,您可以改为使用

\uncover<\j->{\node (m\j) [box] {\txt};}

如果您希望节点在每张幻灯片上停留在相同的位置:

在此处输入图片描述

编辑

如果如评论中所示,描述内容在幻灯片之间也有所不同,那么您可以使用\only\oncover命令的相同技巧。究竟哪个最好,部分取决于个人喜好,部分取决于您的内容,但我可能会使用\uncover

\documentclass{beamer}
\usetheme{Madrid}
\usepackage{tikz}
\usetikzlibrary{arrows.meta,
chains,
positioning,
shadows.blur, shapes.arrows}

\begin{document}

\begin{frame}
\frametitle{~}
\begin{block}{~}
  \uncover<1->{My explanation for the first box is put here.}

  \uncover<2->{My explanation for the second box is put here.}

  \uncover<3->{My explanation for the third box is put here.}

  \uncover<4->{My explanation for the fourth box is put here.}

  \uncover<5->{My explanation for the fifth box is put here.}
\end{block}
\begin{figure}[H]
    \begin{center}
        \begin{tikzpicture}[
        node distance = 2mm and 7mm,
        nodes = {draw, fill=white, blur shadow},
        arj/.style = {draw=gray, ultra thick,-Straight Barb},
        arr/.style = {single arrow, single arrow head extend=1mm,
            minimum height=9mm, shape border rotate=90,
            node contents={~}},
        box/.style = {text width=0.14\linewidth, align=center,inner sep=2pt,
            minimum height=12mm, font=\scriptsize,
            on chain, join = by  arj},
        ]
        \begin{scope}[start chain = A going right]
        \foreach \txt [count=\j] in   {
            Problem Identification, Statistics, Planning,
            Imple\-men\-ta\-tion of Plans, De\-ve\-lop\-ment
        }
        {
            \uncover<\j->{\node (m\j) [box] {\txt};}
        }
        \end{scope}
        \end{tikzpicture}
    \end{center}
    \caption*{\textit{\textbf{Source:} Self Motivated}}
\end{figure}
\end{frame}
\end{document}

生成结果:

在此处输入图片描述

编辑二

如果整个文本块在每张幻灯片之间发生变化,那么您可能需要在块环境上使用修饰符,例如:

\begin{block}{~}<only@1>
  My explanation for the first box is put here.
\end{block}

再次强调,最好的做法取决于你的实际内容,部分取决于个人风格。例如,你可以使用:

\documentclass{beamer}
\usetheme{Madrid}
\usepackage{tikz}
\usetikzlibrary{arrows.meta,
chains,
positioning,
shadows.blur, shapes.arrows}

\begin{document}

\begin{frame}
\frametitle{~}
\begin{block}{~}<only@1>
  My explanation for the first box is put here.
\end{block}
\begin{block}{~}<only@2>
  My explanation for the second box is put here.
\end{block}
\begin{block}{~}<only@3>
  My explanation for the third box is put here.
\end{block}
\begin{block}{~}<only@4>
  My explanation for the fourth box is put here.
\end{block}
\begin{block}{~}<only@5>
  My explanation for the fifth box is put here.
\end{block}

\begin{figure}[H]
    \begin{center}
        \begin{tikzpicture}[
        node distance = 2mm and 7mm,
        nodes = {draw, fill=white, blur shadow},
        arj/.style = {draw=gray, ultra thick,-Straight Barb},
        arr/.style = {single arrow, single arrow head extend=1mm,
            minimum height=9mm, shape border rotate=90,
            node contents={~}},
        box/.style = {text width=0.14\linewidth, align=center,inner sep=2pt,
            minimum height=12mm, font=\scriptsize,
            on chain, join = by  arj},
        ]
        \begin{scope}[start chain = A going right]
        \foreach \txt [count=\j] in   {
            Problem Identification, Statistics, Planning,
            Imple\-men\-ta\-tion of Plans, De\-ve\-lop\-ment
        }
        {
            \uncover<\j->{\node (m\j) [box] {\txt};}
        }
        \end{scope}
        \end{tikzpicture}
    \end{center}
    \caption*{\textit{\textbf{Source:} Self Motivated}}
\end{figure}
\end{frame}
\end{document}

生产

在此处输入图片描述

相关内容