TeX - LaTeX Asked on July 23, 2021
In an animation using Tikz in beamer, I want to draw a bigger box around the boxes in the first two columns i.e. box11
, box12
, box21
and box22
(as I draw in the very last slide using a different method). The bigger box should be animated, i.e., appear on a new slide.
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}
You can use the background library so that the box that includes the others appears in the background.
Here, I did not use this library (I put the code between comments), I used the native possibility of 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}
Correct answer by AndréC on July 23, 2021
Get help from others!
Recent Questions
Recent Answers
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP