TikZ:在流程图中并排放置两个框

TikZ:在流程图中并排放置两个框

我目前正在尝试创建一个大型流程图。我已将示例精简到只有方框的部分,我对此有些困惑(这些方框下面会有更多的方框)。我尝试将这些方框并排放置,如果可能的话,尽可能留出尽可能多的空间,但仍适合页面。我曾尝试以某种方式使用范围,但我无法正确使用它。

以下是 MWE:

\documentclass{article}
\usepackage[latin1]{inputenc}
\usepackage{tikz}
\usetikzlibrary{positioning, fit, calc}
\newcommand{\matr}[1]{\mathbf{#1}} 
\newcommand{\X}{\matr{X}} %Matrix von X


\begin{document}
%Tikz Stuff
\tikzstyle{block} = [rectangle, draw, fill=blue!70!red!10, node distance=10ex, text centered, rounded corners, text width=30ex, minimum height=5ex]
\tikzstyle{intblock} = [rectangle, draw,  node distance=10ex, text centered, rounded corners,  text width=25ex, minimum height=5ex]


\begin{figure}
\centering
\begin{tikzpicture}

\begin{scope}[local bounding box=left]
%First Block
 \node (start) [block, label =below:Input: $\X$, text width=28ex, align = center] {\textbf{1.} Construct knockoffs $\tilde{\X}$};
 \node (a)[below left = 0.5cm of start, align = center]{$n \geq 2p$};
 \node (b) [below right = 0.5cm of start, align=center]{$p \leq n <  2p$\\ Extend rows};
 \node (c) [intblock, below = 1.5cm of start]{Optmize for $\matr{s}$ (SDP/equi-correlation)};
 \node (d) [intblock, below = 1cm of c]{Calculate $\tilde{\X}$ (Theorem \ref{theorem:knockoff})};
 \node (ddd) [below = 0.1cm of d, align=center]{Output: $\tilde{\X}$ satisfying 2.1};
 \node (dd) [fit=(start) (a) (b) (ddd),draw,dotted,black] {};
 \node (e) [block, below = of d]{\textbf{2.} Calculate $(W_1,\dots,W_p)$ obeying 2.2 $\&$ 2.3};
 \end{scope} 
 
  
\draw [->] (start) -| (a); 
\draw [->] (start) -| (b);
\draw [->] (a) |- (c);
\draw [->] (b) |- (c);
\draw [->] (c) -- (d);
\draw [->] (ddd) -- (e);
%First Block end

  %Second block
 \begin{scope}[local bounding box=right, xshift=6cm] 
 \node (xstart) [block, label =below:Input: $\X$] {\textbf{1.} Construct knockoffs  $\tilde{\X}$};
 \node (xa) [intblock, below = of xstart] {Algorithm for knockoff sampler $P_{\tilde{X}|X}$};
 \node (xb) [intblock, below = of xa ] {Sample $\tilde{\X} \sim P_{\tilde{X}|X}$};
 \node (xd) [below = 0.1cm of xb, align=center]{Output: $\tilde{\X}$ $(\approx)$ satisfying Definition 4.2};     
\node (xdd) [fit=(xstart) (xa) (xb) (xd),draw,dotted,black] {};
\node (e) [block, below = of xd]{\textbf{2.} Calculate $(W_1,\dots,W_p)$ obeying  3.1};

\draw [->] (xd) -- (e); 
\end{scope} 
 %Second block end
\end{tikzpicture}
\end{figure}


\end{document}

本质上,我想要左边的第一个框和右边的第二个框。

答案1

在此处输入图片描述

\documentclass{article}
\usepackage[latin1]{inputenc}
\usepackage{tikz}
\usetikzlibrary{positioning, fit, calc}
\newcommand{\matr}[1]{\mathbf{#1}} 
\newcommand{\X}{\matr{X}} %Matrix von X



\begin{document}
%Tikz Stuff
\tikzstyle{block} = [rectangle, draw, fill=blue!70!red!10, node distance=10ex, text centered, rounded corners, text width=30ex, minimum height=5ex]
\tikzstyle{intblock} = [rectangle, draw,  node distance=10ex, text centered, rounded corners,  text width=25ex, minimum height=5ex]


\begin{figure}
\centering
\begin{tikzpicture}

\begin{scope}[local bounding box=left, xshift=-6cm]
%First Block
 \node (start) [block, label =below:Input: $\X$, text width=28ex, align = center] {\textbf{1.} Construct knockoffs $\tilde{\X}$};
 \node (a)[below left = 0.5cm of start, align = center]{$n \geq 2p$};
 \node (b) [below right = 0.5cm of start, align=center]{$p \leq n <  2p$\\ Extend rows};
 \node (c) [intblock, below = 1.5cm of start]{Optmize for $\matr{s}$ (SDP/equi-correlation)};
 \node (d) [intblock, below = 1cm of c]{Calculate $\tilde{\X}$ (Theorem \ref{theorem:knockoff})};
 \node (ddd) [below = 0.1cm of d, align=center]{Output: $\tilde{\X}$ satisfying 2.1};
 \node (dd) [fit=(start) (a) (b) (ddd),draw,dotted,red, ultra thick] {};
 \node (e) [block, below = of d]{\textbf{2.} Calculate $(W_1,\dots,W_p)$ obeying 2.2 $\&$ 2.3};
 \end{scope} 
 
  
\draw [->] (start) -| (a); 
\draw [->] (start) -| (b);
\draw [->] (a) |- (c);
\draw [->] (b) |- (c);
\draw [->] (c) -- (d);
\draw [->] (ddd) -- (e);
%First Block end

  %Second block
 \begin{scope}[local bounding box=right, xshift=3cm] 
 \node (xstart) [block, label =below:Input: $\X$] {\textbf{1.} Construct knockoffs  $\tilde{\X}$};
 \node (xa) [intblock, below = of xstart] {Algorithm for knockoff sampler $P_{\tilde{X}|X}$};
 \node (xb) [intblock, below = of xa ] {Sample $\tilde{\X} \sim P_{\tilde{X}|X}$};
 \node (xd) [below = 0.1cm of xb, align=center]{Output: $\tilde{\X}$ $(\approx)$ satisfying Definition 4.2};     
\node (xdd) [fit=(xstart) (xa) (xb) (xd),draw,dotted,green, ultra thick] {};
\node (e) [block, below = of xd]{\textbf{2.} Calculate $(W_1,\dots,W_p)$ obeying  3.1};

\draw [->] (xd) -- (e); 
\end{scope} 
 %Second block end
\end{tikzpicture}
\end{figure}


\end{document}

相关内容