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 started using Tikz, took a sample of a code and tried to do my own. I'm almost there but I'm struggling on a couple of things.
First, here is my code:

\documentclass{article}  
\usepackage{tikz}  
\usepackage{amssymb}
\usetikzlibrary{arrows}  
\begin{document}  

\begin{tikzpicture}[->,>=stealth',shorten >=1pt,auto,node distance=2.5cm,  
                thick,main node/.style={rectangle,draw,font=\sffamily\Large\bfseries}]  

\node[main node] (1) {1};  
\node[main node] (2) [below of=1] {2};   
\node[main node] (3) [below of=2] {3};   
\node[main node] (4) [right of=1] {$\varnothing$};  
\node[main node] (5) [right of=2] {$\varnothing$};  
\node[main node] (6) [right of=3] {$\varnothing$};  

\path[every node/.style={font=\sffamily\small}]  
(1) edge node [left] {$p_1$} (2)  
    edge node [above] {$1-p_1$} (4)  
(2) edge node [left] {$p_2$} (3)  
    edge node [above] {$1-p_2$} (5)  
(3) edge [bend left] node [left] {$p_3$} (1)  
    edge node [above] {$1-p_3$} (6);
\end{tikzpicture}  
\end{document}

enter image description here

What I would like to change is:
1/ get rid of the rectangle on the empty set nodes
2/ the arrow with p3 on, make it rectangular. Is it possible to adjust how far away it goes on the left to ensure it doesn't clash with something else?
3/ change the distance between the number 1, 2, 3 with the empty set nodes. So basically, expand it to the right.

If anyone could explain me how to change any/all of them, that'll be great!
Cheers

share|improve this question
    
Welcome to TeX.SX! –  Heiko Oberdiek Apr 23 at 22:23

2 Answers 2

up vote 6 down vote accepted

There are almost certainly better ways to do this. (I've been learning for more than an hour but am an extremely slow learner!)

\documentclass[tikz]{standalone}
\usepackage{amssymb}
\usetikzlibrary{arrows,positioning}
\begin{document}

\begin{tikzpicture}
  [ ->,
    >=stealth',
    shorten >=1pt,
    auto,
    node distance=2.5cm,
    thick,
    main node/.style={rectangle,draw,font=\sffamily\Large\bfseries},
    empty node/.style={font=\sffamily\Large\bfseries, xshift=50pt}
    ]% adjust xshift depending on the amount of expansion to the right you require; empty node sets a non-box style for the empty set nodes

  \node[main node] (1) {1};
  \node[main node] (2) [below of=1] {2};
  \node[main node] (3) [below of=2] {3};
  \node[empty node] (4) [right of=1] {$\varnothing$};
  \node[empty node] (5) [right of=2] {$\varnothing$};
  \node[empty node] (6) [right of=3] {$\varnothing$};

  % This node is only here to show how to make sure you go around something: increase 1pt if you want a greater separation
  \node[shape=circle,draw,outer sep=1pt] (extra7) [left of=2] {something else};

  \path[every node/.style={font=\sffamily\small}]
    (1) edge node [left] {$p_1$} (2)
        edge node [above] {$1-p_1$} (4)
    (2) edge node [left] {$p_2$} (3)
        edge node [above] {$1-p_2$} (5)
    (3) edge node [above] {$1-p_3$} (6);

  % this will go to the left (west) of the new node extra7 and will go in straight lines rather than curving
  \path[every node/.style={font=\sffamily\small}, draw]
    (3.west) -- +(0,0) -| (extra7.west)  -- +(0,0) |- node[near start, left] {$p_3$} (1);

\end{tikzpicture}
\end{document}

Diversion around something else

Update

This avoids the syntax which HarishKumar notes can be problematic. Note that it also changes the spacing quite significantly:

\documentclass[tikz]{standalone}
\usepackage{amssymb}
\usetikzlibrary{arrows,positioning}
\begin{document}

\begin{tikzpicture}
  [ ->,
    >=stealth',
    shorten >=1pt,
    auto,
    node distance=2.5cm,
    thick,
    main node/.style={rectangle,draw,font=\sffamily\Large\bfseries},
    empty node/.style={font=\sffamily\Large\bfseries, xshift=50pt}
    ]

  \node[main node] (1) {1};
  \node[main node] (2) [below=of 1] {2};
  \node[main node] (3) [below=of 2] {3};
  \node[empty node] (4) [right=of 1] {$\varnothing$};
  \node[empty node] (5) [right=of 2] {$\varnothing$};
  \node[empty node] (6) [right=of 3] {$\varnothing$};

  \node[shape=circle,draw,outer sep=1pt] (extra7) [left=of 2] {something else};

  \path[every node/.style={font=\sffamily\small}]
    (1) edge node [left] {$p_1$} (2)
        edge node [above] {$1-p_1$} (4)
    (2) edge node [left] {$p_2$} (3)
        edge node [above] {$1-p_2$} (5)
    (3) edge node [above] {$1-p_3$} (6);

  \path[every node/.style={font=\sffamily\small}, draw]
    (3.west) -- +(0,0) -| (extra7.west)  -- +(0,0) |- node[near start, left] {$p_3$} (1);

\end{tikzpicture}
\end{document}

Larger diversion around something else

share|improve this answer
    
Exactly what I had in mind, thanks a lot. Something else node is a nice bonus I can learn from and makes it easier to understand how it works. –  TAllieri Apr 23 at 23:17
    
@TAllieri You're welcome. I keep trying to learn this... [I'm really surprised there were not half a dozen answers by the time I'd finished!] –  cfr Apr 23 at 23:22
    
@HarishKumar OK. Is there a list of Stuff Not To Be Used somewhere? Because the tikz manual itself seems a less than perfectly reliable source of information on this. See, for example, page 237 where the code includes above right of= and below right of=. I'm not sure what the disadvantages of using this syntax are (other than its being 'obsolete') but it would be nice if the documentation at least declared its own examples null and void if that's what they are :(. I think I've learnt the new syntax but I certainly didn't know to 'update' the syntax in the OP's MWE. –  cfr Apr 23 at 23:32
    
@HarishKumar But is there a list somewhere? You said that it was 'obsolete'. If so, presumably that's documented somewhere? –  cfr Apr 23 at 23:36
    
@TAllieri See HarishKumar's comments. I was going to change this in the code I posted but it changes the spacing so it is apparently not merely an alternative, updated syntax but a more substantive change... –  cfr Apr 23 at 23:40
\documentclass{article}
\usepackage{tikz}
\usepackage{amssymb}
\usetikzlibrary{arrows,positioning}
\begin{document}

\begin{tikzpicture}[->,>=stealth',shorten >=1pt,auto,node distance=2.5cm,
                thick,main node/.style={rectangle,draw,font=\sffamily\Large\bfseries}]   %% Use draw = none to get rid of border on all nodes.

\node[main node] (1) {1};
\node[main node] (2) [below = of 1] {2};
\node[main node] (3) [below = of 2] {3};
\node[main node,draw = none] (4) [right = 2in of 1] {$\varnothing$};
\node[main node,draw = none] (5) [right = 2in of 2] {$\varnothing$};
\node[main node,draw = none] (6) [right = 2in of 3] {$\varnothing$};

\path[every node/.style={font=\sffamily\small}]
(1) edge node [left] {$p_1$} (2)
    edge node [above] {$1-p_1$} (4)
(2) edge node [left] {$p_2$} (3)
    edge node [above] {$1-p_2$} (5)
(3) edge [bend left,distance=1.5in] node [left] {$p_3$} (1)
    edge node [above] {$1-p_3$} (6);
\end{tikzpicture}
\end{document}

enter image description here

\documentclass{article}
\usepackage{tikz}
\usepackage{amssymb}
\usetikzlibrary{arrows,positioning}
\begin{document}

\begin{tikzpicture}[->,>=stealth',shorten >=1pt,auto,node distance=2.5cm,
                thick,main node/.style={rectangle,draw,font=\sffamily\Large\bfseries}]   %% Use draw = none to get rid of border on all nodes.

\node[main node] (1) {1};
\node[main node] (2) [below = of 1] {2};
\node[main node] (3) [below = of 2] {3};
\node[main node,draw = none] (4) [right = 2in of 1] {$\varnothing$};
\node[main node,draw = none] (5) [right = 2in of 2] {$\varnothing$};
\node[main node,draw = none] (6) [right = 2in of 3] {$\varnothing$};

\path[every node/.style={font=\sffamily\small}]
(1) edge node [left] {$p_1$} (2)
    edge node [above] {$1-p_1$} (4)
(2) edge node [left] {$p_2$} (3)
    edge node [above] {$1-p_2$} (5)
(3)   edge node [above] {$1-p_3$} (6);
\path[draw,every node/.style={font=\sffamily\small}]
(3.west) -- ([xshift=-2cm]3.west) -- ([xshift=-2cm]1.west) node [midway,left] {$p_3$} -- (1.west);    %% change xshift as you wish
\end{tikzpicture}
\end{document}

enter image description here

share|improve this answer
    
Thanks for the edit, that's how I wanted it. –  TAllieri Apr 23 at 23:29

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.