I'm looking for a package/code snippet to have this kind of diagram. Any ideas?

enter image description here

  • Any code so far? – percusse Jun 25 '14 at 9:38
  • I have a "flowchart" for now, which has a for loop, but it's not how we want it. I can draw the inside boxes, and arrows, but I have no idea how to make that dashed external box with two inside horizontal lines in a proper way, and not having a box + two lines in the middle of the code, hard coded. – adrin Jun 25 '14 at 9:46
  • Have a look at the TikZ-PGF manual, for instance at the shape library (Section 67, p. 701). – TonioElGringo Jun 25 '14 at 9:49
  • Use fit library to draw the external box giving it a name like (foo), and then interpolated coordinates for the horizontal lines in the form ($(foo.north west)!.3333!(foo.south west)$) to denote (in this case) the point at 1/3 of the way from the upper left corner to the lower left corner of that external box. – JLDiaz Jun 25 '14 at 11:29

With the help of the comments and some other sources, I managed to have something which draws what I want, but I bet it's not perfect. I put it here for people who might have the same question, hope it's helpful.



\tikzstyle{block} = [rectangle, draw,
    text width=5em, text centered, rounded corners, minimum height=2em]
\tikzstyle{entity} = [rectangle, draw, text centered]
\tikzstyle{line} = [draw, rounded corners, -latex']

\begin{tikzpicture}[node distance = 4em, auto]
  \node [block] (phi_l) {\footnotesize $\Phi_l \leftarrow \{\}$};
  \node [block, below of=phi_l, text width = 7em, node distance = 5em] (i) {\footnotesize $i \leftarrow 0$};
  \node [block, below of=i, text width = 7em] (i_inc) {\footnotesize $i < N$};
  \node [block, below of=i_inc, text width=12em] (fit_li) {\footnotesize $l_i \leftarrow \text{L1-SVM}(X_{-\Phi_l}, y)$};
  \node [block, below of=fit_li, text width=7em] (up_phi) {\footnotesize $\Phi_l \leftarrow \Phi_l \cup \Phi_{l_i}$};
  \path [line] (fit_li) -- (up_phi);
  \node [block, below of=up_phi] (inc_i) {\footnotesize $i \leftarrow i + 1$};
  \path [line] (up_phi) -- (inc_i);

  \node [block, below of=inc_i, node distance = 5em] (f) {\footnotesize $f \in \Phi_{l_i}$};
  \node [block, below of=f, text width = 13em, node distance = 5em] (phi_f) {\footnotesize$\Phi_f \leftarrow \text{TOP}\left\{ \left( f', \text{MI}\left(f,f'\right)\right) \ri\
ght\} $};
  \node [block, below of=phi_f, text width=10em] (g_f) {\footnotesize $g_f \leftarrow \text{GP}(X_{\Phi_f}, f)$};
  \path [line] (phi_f) -- (g_f);

  \node [block, dashed, fit={($(f.north)+(0,1em)$) (phi_f) (g_f)}] (for2) {};
  \node at (for2.north west) [below right] {for};
  \node [block, dashed, fit={($(i.north)+(0,1em)$) (phi_f) (g_f) (for2) (inc_i)}] (for1) {};
  \node at (for1.north west) [below right] {for};

  \path [draw, dashed] ($(for1.north west)!.13!(for1.south west)$) -- ($(for1.north east)!.13!(for1.south east)$);
  \coordinate (coordinate1) at ($(for1.north west)!.13!(for1.south west)$);
  \node at (coordinate1.east) [below right] {while};
  \path [draw, dashed] ($(for1.north west)!.23!(for1.south west)$) -- ($(for1.north east)!.23!(for1.south east)$);
  \coordinate (coordinate2) at ($(for1.north west)!.23!(for1.south west)$);
  \node at (coordinate2.east) [below right] {do};

  \path [draw, dashed] ($(for2.north west)!.32!(for2.south west)$) -- ($(for2.north east)!.32!(for2.south east)$);
  \coordinate (coordinate3) at ($(for2.north west)!.32!(for2.south west)$);
  \node at (coordinate3.east) [below right] {do};

  \node at ($(for1.north west)!{(1 * 1/2)}!(for1.north east)$) [entity, fill=white] (phi_l_entity) {\footnotesize $\Phi_l$};
  \node at ($(for1.north west)!{(1 * 1/4)}!(for1.north east)$) [entity, fill=white] (X_entity) {\footnotesize $X$};
  \node at ($(for1.north west)!{(3 * 1/4)}!(for1.north east)$) [entity, fill=white] (y_entity) {\footnotesize $y$};
  \path [line] (phi_l) -- (phi_l_entity);

  \node at ($(for2.north west)!{(1 * 1/3)}!(for2.north east)$) [entity, fill=white] (X_entity2) {\footnotesize $X$};
  \node at ($(for2.north west)!{(2 * 1/3)}!(for2.north east)$) [entity, fill=white] (phi_li_entity) {\footnotesize $\Phi_{l_i}$};


enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.