Beamer:增加包含 Tikz 图片的两个矩形框的高度

Beamer:增加包含 Tikz 图片的两个矩形框的高度

我有两个tikz pictures包裹在两个矩形盒子中并连接起来tikz arrow以供说明,beamer如下所示:

\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]                     % <---
            \path[arr]  (n1.south)   to[bend left=45]    (n2.east);    % <---
        \end{tikzpicture}
    \end{frame}
\end{document}

这是其输出

我想要的是

我希望height第一个矩形 tikz 的垂直向下增加以提高可见性,第二个矩形 tikz 的垂直向上增加以提高可见性。 距离总是会相应减小。

笔记

重量不需要增加。

答案1

使用@Symbol 1 的解决方案为了获取框架高度(即不包含页眉和页脚的高度),我们可以将其绘制为一张 TikZ 图片,其中您的图表是一个单元格矩阵的内容。

几点说明:

  • 矩阵的设置(如描边颜色、锚点和)rounded corners也适用于矩阵内的路径/节点。这就是为什么其中一些被恢复为blackanchor=centersharp counters作为样式的一部分every cell(通过使用cells

  • 我把所有东西都放在一条路径上,这样我就可以behind path将粉色边缘放在顶部节点下方。这也需要in front of path添加到cells

  • 注意use matrix backgroundinboxfill matrixin 的用法\myDrawing。这将设置使用与矩阵相同填充颜色的样式。

    不过,在这个简单的情况下,您只需添加draw=blackcells而不是black(将所有颜色设置为黑色),然后fill在节点上使用,它也会拾取矩阵的填充颜色。

代码

\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}

输出

在此处输入图片描述

答案2

  • 不要嵌套TikZ图片,可能会发生奇怪的事情
  • 不要使用邪恶的shrink框架选项

相反,你可以绘制两个单独的 tikz 图片并用箭头连接它们:

\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[->,red!80!black,line width=1mm, -{Stealth} ] (a.south) to[bend left=55] (b.east);
            \end{tikzpicture}
    \end{frame}
\end{document}

在此处输入图片描述

相关内容