在 Beamer 中使用 tikz 制作多个动画框

在 Beamer 中使用 tikz 制作多个动画框

在 Beamer 中使用 Tikz 制作的动画中,我想在前两列(即box11、和box12)的框周围绘制一个更大的框(因为我在最后一张幻灯片中使用了不同的方法绘制)。更大的框应该是动画,即出现在新幻灯片上。box21box22

\documentclass{beamer}
\mode<presentation>{\usetheme{Madrid}}

\usepackage{tikz}
\usetikzlibrary{arrows.meta,backgrounds,fit,matrix}


\tikzstyle{bigbox} = [minimum size=3cm,draw=blue!50, thick, fill=blue!10, rounded corners, rectangle]
\tikzstyle{box} = [minimum size=1.5cm, rounded corners,rectangle, fill=blue!50]
\tikzstyle{arrow} = [thick,->,>=stealth]

\begin{document}


\begin{frame}[t]
    

\begin{tikzpicture}[
every edge/.style = {draw, thick, -Stealth}
                        ]

\node (box11) [box] {11};

\node<+(1)-> (box12) [box, right of=box11,xshift=2cm] {12};

\node<+(1)-> (box13) [box, right of=box12,xshift=2cm] {13};

\node<+(1)-> (box21) [box, below of=box11,yshift=-2cm] {21};

\node<+(1)-> (box22) [box, right of=box21,xshift=2cm] {22};

\node<+(1)-> (box23) [box, right of=box22,xshift=2cm] {23};

%\node (box) [bigbox] {P};

\path[transform canvas={yshift=+2mm}]<+(1)->
    (box11) edge (box12)
    (box12) edge (box13)
    (box21) edge (box22)
    (box22) edge (box23);
    
\path[transform canvas={yshift=-2mm}]<+(1)->
    (box12) edge (box11)
    (box13) edge (box12)
    (box22) edge (box21)
    (box23) edge (box22);

\path[transform canvas={xshift=+2mm}]<+(1)->
    (box12) edge (box22)
    (box13) edge (box23);
    
\path[transform canvas={xshift=-2mm}]<+(1)->
    (box22) edge (box12)
    (box23) edge (box13);

\node<+(1)-> at (1,-1.5) [font=\sffamily] {Text};
\end{tikzpicture}
\end{frame}


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{frame}[fragile]
    

\begin{tikzpicture}
\tikzstyle{bigbox} = [minimum size=3cm,draw=blue!50, thick, fill=blue!10, rounded corners, rectangle]
\tikzstyle{box} = [minimum size=1.5cm, rounded corners,rectangle, fill=blue!50]


\matrix[row sep=20mm, column sep=15mm, inner sep=7mm, bigbox, matrix of nodes, every node/.style=box] {
11 & 12\\
21 & 22\\
};

\node (h1) [yshift=0mm] {Text};

\matrix[xshift=6cm,row sep=20mm, column sep=15mm, inner sep=7mm, matrix of nodes, every node/.style=box] {
13\\
23\\
};


\end{tikzpicture}
\end{frame}


\end{document}

答案1

您可以使用背景库,以便包含其他内容的框出现在背景中。

在这里,我没有使用这个库(我把代码放在注释之间),我使用了 TikZ 的原生可能性。

\pgfdeclarelayer{background layer}
\pgfsetlayers{background layer,main}

截屏

\documentclass{beamer}
\mode<presentation>{\usetheme{Madrid}}

\usepackage{tikz}
\usetikzlibrary{arrows.meta,backgrounds,fit,matrix}
%\usetikzlibrary{backgrounds}

\tikzstyle{bigbox} = [minimum size=3cm,draw=blue!50, thick, fill=blue!10, rounded corners, rectangle]
\tikzstyle{box} = [minimum size=1.5cm, rounded corners,rectangle, fill=blue!50]
\tikzstyle{arrow} = [thick,->,>=stealth]

\begin{document}
\pgfdeclarelayer{background layer}
\pgfsetlayers{background layer,main}

\begin{frame}[t]
    

\begin{tikzpicture}[
every edge/.style = {draw, thick, -Stealth}
                        ]
\path (-1,-1)rectangle(1,1);
\node (box11) [box] {11};

\node<+(1)-> (box12) [box, right of=box11,xshift=2cm] {12};

\node<+(1)-> (box13) [box, right of=box12,xshift=2cm] {13};

\node<+(1)-> (box21) [box, below of=box11,yshift=-2cm] {21};

\node<+(1)-> (box22) [box, right of=box21,xshift=2cm] {22};

\node<+(1)-> (box23) [box, right of=box22,xshift=2cm] {23};

%\node (box) [bigbox] {P};

\path[transform canvas={yshift=+2mm}]<+(1)->
    (box11) edge (box12)
    (box12) edge (box13)
    (box21) edge (box22)
    (box22) edge (box23);
    
\path[transform canvas={yshift=-2mm}]<+(1)->
    (box12) edge (box11)
    (box13) edge (box12)
    (box22) edge (box21)
    (box23) edge (box22);

\path[transform canvas={xshift=+2mm}]<+(1)->
    (box12) edge (box22)
    (box13) edge (box23);
    
\path[transform canvas={xshift=-2mm}]<+(1)->
    (box22) edge (box12)
    (box23) edge (box13);
    
%\begin{scope}[on background layer={color=yellow}]
%\node<+->[draw,fill=green!50,fill opacity=.5,fit= (box11) (box22)]{box};
%\end{scope}

\begin{pgfonlayer}{background layer}
\node<+->[draw,fill=green!50,fit= (box11) (box22)]{box};
\end{pgfonlayer}
\end{tikzpicture}
\end{frame}


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%\begin{frame}[fragile]
%    
%
%\begin{tikzpicture}
%\tikzstyle{bigbox} = [minimum size=3cm,draw=blue!50, thick, fill=blue!10, rounded corners, rectangle]
%\tikzstyle{box} = [minimum size=1.5cm, rounded corners,rectangle, fill=blue!50]
%
%
%\matrix[row sep=20mm, column sep=15mm, inner sep=7mm, bigbox, matrix of nodes, every node/.style=box] {
%11 & 12\\
%21 & 22\\
%};
%
%\node (h1) [yshift=0mm] {Text};
%
%\matrix[xshift=6cm,row sep=20mm, column sep=15mm, inner sep=7mm, matrix of nodes, every node/.style=box] {
%13\\
%23\\
%};
%
%
%\end{tikzpicture}
%\end{frame}


\end{document}

相关内容