Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I'm trying to draw the a structure that has multiple chains from the start, based on this example http://www.texample.net/tikz/examples/assignment-structure/

What I have so far is:

\documentclass[]{article}
\usepackage{tikz}
\usetikzlibrary{calc,trees,positioning,arrows,chains,shapes.geometric,%
    decorations.pathreplacing,decorations.pathmorphing,shapes,%
    matrix,shapes.symbols}
\tikzset{
>=stealth',
  punktchain/.style={
    rectangle, 
    rounded corners, 
    % fill=black!10,
    draw=black, very thick,
    text width=10em, 
    minimum height=3em, 
    text centered, 
    on chain},
  line/.style={draw, thick, <-},
  element/.style={
    tape,
    top color=white,
    bottom color=blue!50!black!60!,
    minimum width=8em,
    draw=blue!40!black!90, very thick,
    text width=10em, 
    minimum height=3.5em, 
    text centered, 
    on chain},
  every join/.style={->, thick,shorten >=1pt},
  decoration={brace},
  tuborg/.style={decorate},
  tubnode/.style={midway, right=2pt},
}

\begin{document}

\begin{figure}[h]
\centering
\begin{tikzpicture}[node distance=.8cm,
  start chain=1 going below, start chain=2 going below]
     \node[punktchain, join] (start) {Static MC};

     \node[punktchain, join] (probf)      {Uniform Generator};
     \node[punktchain, join] (u) {U};
     \node[punktchain, join] (rules) {Transformation Rules};
     \node[punktchain, join, ] (simrv) {Simulated r.v. X};
      \node (loop) [punktchain ]  {Simulation algorithm (loop)};
        %Left Branch 
        \begin{scope}[start branch=left,
                every join/.style={->, thick, shorten <=1pt}, ]
                \node[punktchain, on chain=going left, join=by {<-}] (var) {Variance Reduction};
        \end{scope}

        %Lower branch
        \node[punktchain, join] (paths) {Sample paths};
        \node[punktchain, join] (law) {Law of large numbers};
         \node[punktchain, join] (estim) {Monte Carlo Estimation}; 
    \draw[tuborg] let
    \p1=(loop.west), \p2=(loop.east) in
    ($(\x1,\y1+2.5em)$) -- ($(\x2,\y2+2.5em)$) node[below, midway]  {};
\end{tikzpicture}
\caption{}
\label{fig:6forces}
\end{figure}
\end{document}

Which looks like this so far Partial diagram

What I'd like to do from here on, is what I've sketched above in black color. That is, I want another chain to the right of the existing that links up at the (loop) node and has a fork in it as well.

Can somebody give me some help? I've been going over the tikz manual but I'm not getting very far.

Cheers, Christos

share|improve this question

2 Answers 2

up vote 3 down vote accepted

This is a first trial since I didn't understood well how you would like to connect the two chains near the loop node.

My solution leads to:

enter image description here

Here is the code:

\documentclass[]{article}
\usepackage{tikz}
\usetikzlibrary{calc,trees,positioning,arrows,chains,shapes.geometric,%
    decorations.pathreplacing,decorations.pathmorphing,shapes,%
    matrix,shapes.symbols}
\tikzset{
>=stealth',
  punktchain/.style={
    rectangle, 
    rounded corners, 
    % fill=black!10,
    draw=black, very thick,
    text width=10em, 
    minimum height=3em, 
    text centered, 
    on chain},
   small punktchain/.style={
    rectangle, 
    rounded corners, 
    % fill=black!10,
    draw=black, very thick,
    text width=5em, 
    minimum height=3em, 
    text centered, 
    on chain},
  line/.style={draw, thick, <-},
  element/.style={
    tape,
    top color=white,
    bottom color=blue!50!black!60!,
    minimum width=8em,
    draw=blue!40!black!90, very thick,
    text width=10em, 
    minimum height=3.5em, 
    text centered, 
    on chain},
  every join/.style={->, thick,shorten >=1pt},
  decoration={brace},
  tuborg/.style={decorate},
  tubnode/.style={midway, right=2pt},
}

\begin{document}

\begin{figure}[h]
\centering
\begin{tikzpicture}[node distance=.8cm,
  start chain=1 going below, start chain=2 going below]
     \node[punktchain, join] (start) {Static MC};

     \node[punktchain, join] (probf)      {Uniform Generator};
     \node[punktchain, join] (u) {U};
     \node[punktchain, join] (rules) {Transformation Rules};
     \node[punktchain, join, ] (simrv) {Simulated r.v. X};
      \node (loop) [punktchain ]  {Simulation algorithm (loop)};
        %Left Branch 
        \begin{scope}[start branch=left,
                every join/.style={->, thick, shorten <=1pt}, ]
                \node[punktchain, on chain=going left, join=by {<-}] (var) {Variance Reduction};
        \end{scope}

        %Lower branch
        \node[punktchain, join] (paths) {Sample paths};
        \node[punktchain, join] (law) {Law of large numbers};
         \node[punktchain, join] (estim) {Monte Carlo Estimation}; 
    \draw[tuborg] let
    \p1=(loop.west), \p2=(loop.east) in
    ($(\x1,\y1+2.5em)$) -- ($(\x2,\y2+2.5em)$) node[below, midway]  {};

    % SECOND CHAIN
    \node[punktchain, right=2cm of start] (x) {...};
    \node[punktchain,join] (y) {...};
    \node[punktchain, join] (z) {...}
    child{node[small punktchain, join, right=1cm of rules] (wa) {...}
    child{node[small punktchain, join] (wc) {...}}
     }
    child[->,thick]{node[small punktchain,right=2cm of wa] (wb) {...}
    child{node[small punktchain, join] (wd) {...}}}
    ;

    % connections with the first one
    \draw[thick,->](simrv.south)--($(simrv.south)+(0,-1em)$);

    \draw[thick] (wd.south)--($(wd.south)+(0,-1em)$);
    \draw[thick] (wc.south)--($(wc.south)+(0,-1em)$);
    \draw[thick,->] ($(wd.south)+(0,-1em)$)--($(simrv.south)+(0,-1em)$);
    \draw[thick,->]($(simrv.south)+(0,-1em)$)--(loop.north);


\end{tikzpicture}
\caption{}
\label{fig:6forces}
\end{figure}
\end{document}

The key points in my solution are:

  1. the definition of the starting node of the second chain (called x) placed with in position right=2cm of start;
  2. use the syntax of trees to separate the chain in two sub-chains from node z;
  3. use a new kind of element, small punktchain, to represent nodes in the sub-chains; it basically is a replica of the style punktchain just a bit small;
  4. use the calc library to connect the two sub-chains with the initial chain (this part could be improved as soon as more details will be provided).
share|improve this answer
    
Thanks very much Claudio, this was immensely useful. I would have wasted a lot of time, for just one graph. –  cmdel Jul 13 '12 at 9:21
    
@cmdel: you're welcome. :) –  Claudio Fiandrino Jul 13 '12 at 9:37

A little reminder about the chains

\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{chains}

\begin{document}
\begin{tikzpicture}
\begin{scope}[start chain=1 going below,start chain=2 going right]
\node[on chain=1] (A) {A};
\node[on chain=1] (C) {C};
\node[on chain=1] (D) {D};
\node[on chain=1] (G) {G};
\node[on chain=1] (H) {H};
\chainin (A);
\node[on chain=2,] (B) {B};
\node[continue chain=going below,on chain=2] (E) {E};
\node[on chain=2] (F) {F};
\end{scope}
\end{tikzpicture}
\end{document}

enter image description here

share|improve this answer
    
Oh.. I had never used the library chains: it's really helpfully in this case (at least I think my example could be simplified a bit ;) ). –  Claudio Fiandrino Jul 12 '12 at 17:57
    
@ClaudioFiandrino indeed it's more flexible than it looks. –  percusse Jul 12 '12 at 18:17

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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