1

I have two tikz pictures wrapped in two rectangular boxes and connected with tikz arrow for illustration on beamer as demonstrated below:

\documentclass[xcolor=dvipsnames,svgnames]{beamer}
%\usepackage{pgfpages}
%\pgfpagesuselayout{2 on 1}[a4paper]

\usetheme{Madrid} \useoutertheme[subsection=false]{miniframes} % Alternatively: miniframes, infolines, split \useinnertheme{circles} \makeatletter \def\beamer@writeslidentry{\clearpage\beamer@notesactions} \makeatother %https://tex.stackexchange.com/questions/699171/put-two-tikz-pictures-in-adjacently-opposite-boxes-a-beamer

\usepackage{tikz} \usetikzlibrary{shapes.arrows,shadows.blur,positioning,arrows.meta, bending,decorations.text,decorations.pathreplacing} \usepackage{eqparbox}

\newbox\eqnodebox \tikzset{equal size/.style={execute at begin node={\setbox\eqnodebox=\hbox\bgroup}, execute at end node={\egroup\eqmakebox[#1][c]{\copy\eqnodebox}}}, equal size/.default=A,} % Preamble for textbox connected wit arrow \usetikzlibrary{positioning, shapes.arrows,shadows.blur}

%\usepackage{better-beamer}

\usepackage{tikz} \usetikzlibrary{shapes.geometric,arrows}

\begin{document}
\begin{frame}[label = {frm15}, fragile, shrink=20] \frametitle{\textbf{Moving Block Bootstrap}} \begin{tikzpicture}[ node distance = 200mm and 40mm, % boxes distance box/.style = {draw=#1, rounded corners, thick, fill=#1!15}, % <--- arr/.style = {draw=red!80!black,line width=5mm, shorten >=-3.5ex, % <--- arrow tickness -{Stealth[width=0pt 3,inset=0pt 1, flex]} } % <--- arrow head ] \newcommand\B{\mathbf{B}}
\node[box=cyan] (n1)
{\begin{tikzpicture} % draw horizontal line

                \draw (0,0) -- (17,0);



                % draw vertical lines
                \foreach \x in {0.5,1.5,2.5,7.5,8.5,9.5,14.5,16.5}
                \draw (\x cm,5pt) -- (\x cm,-0pt);
                % draw nodes
                \draw (0.5,0) node[above=5pt] {$ x_{1} $} node[above=5pt] {$\rm   $};
                \draw (1.6,0) node[above=5pt] {$ x_{2} $} node[above=5pt] {$\rm   $};
                \draw (2.5,0) node[above=3pt] {$ x_{3} $} node[above=5pt] {$\rm   $};
                \draw (5,0) node[above=3pt] {$ \ldots $};
                \draw (7.5,0) node[above=3pt] {$ x_{l} $} node[above=5pt] {$\rm   $};
                \draw (8.5,0) node[above=3pt] {$ x_{l+1} $} node[above=5pt] {$\rm   $};
                \draw (9.5,0) node[above=3pt] {$ x_{l+2} $} node[above=5pt] {$\rm   $};
                \draw (12,0) node[above=3pt] {$ \ldots $};
                \draw (14.5,0) node[above=3pt] {$ x_{l*b} $} node[above=5pt] {$\rm   $};
                \draw (15.75,0) node[above=3pt] {$ \ldots $};
                \draw (16.5,0) node[above=5pt] {$ x_{n} $} node[above=5pt] {$\rm   $};

                \draw [-] (0.5,-0.1) -- (0.5,-0.5);
                \draw [-] (7.5,-0.1) -- (7.5,-0.5);
                \draw [-] (0.5,-0.3) --node [midway,anchor=center,fill=white,inner sep=0.5pt] {$ B_{1} $} (7.5,-0.3);

                \draw [-] (1.5,-0.8) -- (1.5,-1.2);
                \draw [-] (8.5,-0.8) -- (8.5,-1.2);
                \draw [-] (1.5,-1.0) --node [midway,anchor=center,fill=white,inner sep=0.5pt] {$ B_{2} $} (8.5,-1.0);

                \draw [-] (2.5,-1.5) -- (2.5,-1.9);
                \draw [-] (9.5,-1.5) -- (9.5,-1.9);
                \draw [-] (2.5,-1.7) --node [midway,anchor=center,fill=white,inner sep=0.5pt] {$ B_{3} $} (9.5,-1.7);

                %\draw [-] (1.5,-0.1) -- (1.5,-0.8);
                \draw [-] (14.5,-0.1) -- (14.5,-0.5);
                \draw [-] (11.0,-0.3) --node [midway,anchor=center,fill=white,inner sep=0.5pt] {$ B_{k} $} (14.5,-0.3);

                \draw (10.75,-0.3) node {$ \ldots $};

        \end{tikzpicture}};
        \node[box=blue, below left=of n1] (n2)   
        {\begin{tikzpicture}
                % draw horizontal line   

                \draw (0,0) -- (17,0);



                % draw vertical lines
                \foreach \x in {0.5,1.5,2.5,7.5,8.5,9.5,14.5,16.5}
                \draw (\x cm,5pt) -- (\x cm,-0pt);
                % draw nodes
                \draw (0.5,0) node[above=5pt] {$ x_{1} $} node[above=5pt] {$\rm   $};
                \draw (1.6,0) node[above=5pt] {$ x_{2} $} node[above=5pt] {$\rm   $};
                \draw (2.5,0) node[above=3pt] {$ x_{3} $} node[above=5pt] {$\rm   $};
                \draw (5,0) node[above=3pt] {$ \ldots $};
                \draw (7.5,0) node[above=3pt] {$ x_{l} $} node[above=5pt] {$\rm   $};
                \draw (8.5,0) node[above=3pt] {$ x_{l+1} $} node[above=5pt] {$\rm   $};
                \draw (9.5,0) node[above=3pt] {$ x_{l+2} $} node[above=5pt] {$\rm   $};
                \draw (12,0) node[above=3pt] {$ \ldots $};
                \draw (14.5,0) node[above=3pt] {$ x_{l*b} $} node[above=5pt] {$\rm   $};
                \draw (15.75,0) node[above=3pt] {$ \ldots $};
                \draw (16.5,0) node[above=5pt] {$ x_{n} $} node[above=5pt] {$\rm   $};

                \draw [-] (0.5,-0.1) -- (0.5,-0.5);
                \draw [-] (7.5,-0.1) -- (7.5,-0.5);
                \draw [-] (0.5,-0.3) --node [midway,anchor=center,fill=white,inner sep=0.5pt] {$ B_{1} $} (7.5,-0.3);

                \draw [-] (1.5,-0.8) -- (1.5,-1.2);
                \draw [-] (8.5,-0.8) -- (8.5,-1.2);
                \draw [-] (1.5,-1.0) --node [midway,anchor=center,fill=white,inner sep=0.5pt] {$ B_{2} $} (8.5,-1.0);

                \draw [-] (2.5,-1.5) -- (2.5,-1.9);
                \draw [-] (9.5,-1.5) -- (9.5,-1.9);
                \draw [-] (2.5,-1.7) --node [midway,anchor=center,fill=white,inner sep=0.5pt] {$ B_{3} $} (9.5,-1.7);

                %\draw [-] (1.5,-0.1) -- (1.5,-0.8);
                \draw [-] (14.5,-0.1) -- (14.5,-0.5);
                \draw [-] (11.0,-0.3) --node [midway,anchor=center,fill=white,inner sep=0.5pt] {$ B_{k} $} (14.5,-0.3);

                \draw (10.75,-0.3) node {$ \ldots $};

        \end{tikzpicture}};
        \scoped[opacity=0.3,transparency group]                     % &lt;---
        \path[arr]  (n1.south)   to[bend left=45]    (n2.east);    % &lt;---
    \end{tikzpicture}
\end{frame}

\end{document}

Here is its output.

What I Want

I want the height of the first-rectangular tikz to increase vertically downward for visibility and the second-rectangular tikz to increase vertically upward for visibility. Invariably, the distance will reduce accordingly.

Note

Weights need not increase.

economia
  • 259

2 Answers2

2

Using @Symbol 1's solution for getting access to the frame height (i.e. the height without the headers and footers) we can draw this as one TikZ picture where your diagrams are the content of a matrix with one cell.

A few notes:

  • a matrix' settings like stroke color, anchors and rounded corners gets also applied to the paths/nodes inside a matrix. This is why some of these are reverted to black, anchor=center and sharp counters as part of the every cell style (used via cells)

  • I've put everything on one path which allows me do use behind path to put the pink edge below the top node. This also needs in front of path added to cells.

  • Note the use matrix background usage in box and the fill matrix in \myDrawing. This sets up a style that uses the same fill color as the one for the matrix.

    Though, in this simple case, you could just add draw=black to the cells instead of black (which sets all colors to black) and then use just fill on the nodes and it will pick up the matrix' fill color as well.

Code

\documentclass[xcolor=dvipsnames,svgnames]{beamer}
\usetheme{Madrid}
\useoutertheme[subsection=false]{miniframes} % Alternatively: miniframes, infolines, split
\useinnertheme{circles}
\usepackage{tikz}
\usetikzlibrary{arrows.meta, bending}
\newcommand*\myDrawing{
  % draw horizontal line
  \draw (0,0) -- (17,0);
  % draw vertical lines with labels
  \foreach[count=\i] \x/\l in {0.5/1,   1.5/2,   2.5/3,
                               7.5/l,   8.5/l+1, 9.5/l+2,
                              14.5/lb, 16.5/n}
    \draw (\x, 5pt) node[above](n\i) {$x_{\l}$} -- (\x, 0pt);
  % draw nodes
  \path (n3) -- node{$\cdots$} (n4)
        (n6) -- node{$\cdots$} (n7)
             -- node{$\cdots$} (n8);
  \path[Bar Sep-Bar Sep, nodes={fill matrix, inner sep=+.1em}]
    (n1|-0,-0.3) edge node {$ B_{1} $} (n4|-0,-0.3)
    (n2|-0,-1.0) edge node {$ B_{2} $} (n5|-0,-1.0)
    (n3|-0,-1.7) edge node {$ B_{3} $} (n6|-0,-1.7)
    (11.0,-0.3) edge[arrows={... - Bar Sep}] node {$ B_{k} $} (n7|-0,-0.3);
}
\tikzset{
  use matrix background/.style={fill matrix/.style={fill={#1}}},
  box/.style = {draw=#1, rounded corners, thick, fill=#1!15, use matrix background={#1!15}},
  arr/.style = {draw=red!80!black,line width=2mm, shorten <=+-2\pgflinewidth,
                -{Stealth[width=+0pt +3, inset=+0pt +1, flex]}},
  Bar Sep/.tip={Bar[sep=+0pt +-.5]},
  .../.tip={[sep=0pt 1]% https://tex.stackexchange.com/a/120429
      Round Cap[]. Circle[length=0pt 1] Circle[length=0pt 1] Circle[length=0pt 1, sep=0pt]},
  edges have transparency group/.style={% https://tex.stackexchange.com/a/688111
    execute at begin to={\scope[transparency group,#1]},
    execute at end to=\endscope}}
\makeatletter
\NewDocumentEnvironment{beamershrinkcheat}{+b}{% https://tex.stackexchange.com/a/278434
  \global\beamer@shrinktrue
  \long\gdef\beamer@shrinkframebox{%
    \setbox\beamer@framebox=\vbox to \beamer@frametextheight{%
      \edef\frameheight{\the\beamer@frametextheight}#1}}}{}
\makeatother
\begin{document}
\begin{frame}{Moving Block Bootstrap}
\begin{beamershrinkcheat}
\begin{tikzpicture}[cells={black, scale=.5, transform shape, in front of path, sharp corners, anchor=center}]
\path
 node[matrix, box=cyan, anchor=north east]
   at (\framewidth, \frameheight) (m1) {\myDrawing\\}
 node[matrix, box=blue, anchor=south west, behind path]
   at (0,0) (m2) {\myDrawing\\}
 [edges have transparency group={opacity=.3}, behind path]
   (m1.south) edge[arr, in=45, out=-45] ([xshift=-3ex]m2.east);
\end{tikzpicture}
\end{beamershrinkcheat}
\end{frame}
\end{document}

Output

enter image description here

Qrrbrbirlbel
  • 119,821
1
  • Don't nest TikZpictures, strange things can happen
  • Don't use the evil shrink frame option

Instead you could draw two separate tikz pictures and connect them with an arrow:

\documentclass[xcolor=dvipsnames,svgnames]{beamer}

\usepackage{tikz} \usetikzlibrary{shapes.arrows,shadows.blur,positioning,arrows.meta, bending,decorations.text,decorations.pathreplacing,fit,shapes.geometric,arrows}

\setbeamerfont{frametitle}{series=\bfseries}

\begin{document}
\begin{frame}[label = {frm15}] \frametitle{Moving Block Bootstrap}

        \newcommand\B{\mathbf{B}}   
        \hfill\begin{tikzpicture}[transform shape,scale=0.5,remember picture]
                % draw horizontal line   

                \draw (0,0) -- (17,0);



                % draw vertical lines
                \foreach \x in {0.5,1.5,2.5,7.5,8.5,9.5,14.5,16.5}
                \draw (\x cm,5pt) -- (\x cm,-0pt);
                % draw nodes
                \draw (0.5,0) node[above=5pt] {$ x_{1} $} node[above=5pt] {$\rm   $};
                \draw (1.6,0) node[above=5pt] {$ x_{2} $} node[above=5pt] {$\rm   $};
                \draw (2.5,0) node[above=3pt] {$ x_{3} $} node[above=5pt] {$\rm   $};
                \draw (5,0) node[above=3pt] {$ \ldots $};
                \draw (7.5,0) node[above=3pt] {$ x_{l} $} node[above=5pt] {$\rm   $};
                \draw (8.5,0) node[above=3pt] {$ x_{l+1} $} node[above=5pt] {$\rm   $};
                \draw (9.5,0) node[above=3pt] {$ x_{l+2} $} node[above=5pt] {$\rm   $};
                \draw (12,0) node[above=3pt] {$ \ldots $};
                \draw (14.5,0) node[above=3pt] {$ x_{l*b} $} node[above=5pt] {$\rm   $};
                \draw (15.75,0) node[above=3pt] {$ \ldots $};
                \draw (16.5,0) node[above=5pt] {$ x_{n} $} node[above=5pt] {$\rm   $};

                \draw [-] (0.5,-0.1) -- (0.5,-0.5);
                \draw [-] (7.5,-0.1) -- (7.5,-0.5);
                \draw [-] (0.5,-0.3) --node [midway,anchor=center,fill=white,inner sep=0.5pt] {$ B_{1} $} (7.5,-0.3);

                \draw [-] (1.5,-0.8) -- (1.5,-1.2);
                \draw [-] (8.5,-0.8) -- (8.5,-1.2);
                \draw [-] (1.5,-1.0) --node [midway,anchor=center,fill=white,inner sep=0.5pt] {$ B_{2} $} (8.5,-1.0);

                \draw [-] (2.5,-1.5) -- (2.5,-1.9);
                \draw [-] (9.5,-1.5) -- (9.5,-1.9);
                \draw [-] (2.5,-1.7) --node [midway,anchor=center,fill=white,inner sep=0.5pt] {$ B_{3} $} (9.5,-1.7);

                %\draw [-] (1.5,-0.1) -- (1.5,-0.8);
                \draw [-] (14.5,-0.1) -- (14.5,-0.5);
                \draw [-] (11.0,-0.3) --node [midway,anchor=center,fill=white,inner sep=0.5pt] {$ B_{k} $} (14.5,-0.3);

                \draw (10.75,-0.3) node {$ \ldots $};
                \node[draw=cyan,fill=cyan,fill opacity=0.2, rounded corners, thick, fit=(current bounding box)] (a) {};
        \end{tikzpicture}

\vfill

        \begin{tikzpicture}[transform shape,scale=0.5,remember picture]
                % draw horizontal line   

                \draw (0,0) -- (17,0);



                % draw vertical lines
                \foreach \x in {0.5,1.5,2.5,7.5,8.5,9.5,14.5,16.5}
                \draw (\x cm,5pt) -- (\x cm,-0pt);
                % draw nodes
                \draw (0.5,0) node[above=5pt] {$ x_{1} $} node[above=5pt] {$\rm   $};
                \draw (1.6,0) node[above=5pt] {$ x_{2} $} node[above=5pt] {$\rm   $};
                \draw (2.5,0) node[above=3pt] {$ x_{3} $} node[above=5pt] {$\rm   $};
                \draw (5,0) node[above=3pt] {$ \ldots $};
                \draw (7.5,0) node[above=3pt] {$ x_{l} $} node[above=5pt] {$\rm   $};
                \draw (8.5,0) node[above=3pt] {$ x_{l+1} $} node[above=5pt] {$\rm   $};
                \draw (9.5,0) node[above=3pt] {$ x_{l+2} $} node[above=5pt] {$\rm   $};
                \draw (12,0) node[above=3pt] {$ \ldots $};
                \draw (14.5,0) node[above=3pt] {$ x_{l*b} $} node[above=5pt] {$\rm   $};
                \draw (15.75,0) node[above=3pt] {$ \ldots $};
                \draw (16.5,0) node[above=5pt] {$ x_{n} $} node[above=5pt] {$\rm   $};

                \draw [-] (0.5,-0.1) -- (0.5,-0.5);
                \draw [-] (7.5,-0.1) -- (7.5,-0.5);
                \draw [-] (0.5,-0.3) --node [midway,anchor=center,fill=white,inner sep=0.5pt] {$ B_{1} $} (7.5,-0.3);

                \draw [-] (1.5,-0.8) -- (1.5,-1.2);
                \draw [-] (8.5,-0.8) -- (8.5,-1.2);
                \draw [-] (1.5,-1.0) --node [midway,anchor=center,fill=white,inner sep=0.5pt] {$ B_{2} $} (8.5,-1.0);

                \draw [-] (2.5,-1.5) -- (2.5,-1.9);
                \draw [-] (9.5,-1.5) -- (9.5,-1.9);
                \draw [-] (2.5,-1.7) --node [midway,anchor=center,fill=white,inner sep=0.5pt] {$ B_{3} $} (9.5,-1.7);

                %\draw [-] (1.5,-0.1) -- (1.5,-0.8);
                \draw [-] (14.5,-0.1) -- (14.5,-0.5);
                \draw [-] (11.0,-0.3) --node [midway,anchor=center,fill=white,inner sep=0.5pt] {$ B_{k} $} (14.5,-0.3);

                \draw (10.75,-0.3) node {$ \ldots $};
                \node[draw=blue,fill=blue,fill opacity=0.2, rounded corners, thick, fit=(current bounding box)] (b) {};
        \end{tikzpicture}

        \begin{tikzpicture}[remember picture,overlay]
        \draw[-&gt;,red!80!black,line width=1mm, -{Stealth} ] (a.south) to[bend left=55] (b.east);
        \end{tikzpicture}
\end{frame}

\end{document}

enter image description here