TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Here is my current code for the picture:


\tikzset{level 1/.style={level distance=0.7cm, sibling distance=3cm}}
\tikzset{level 2/.style={level distance=0.7cm, sibling distance=6cm}}

\tikzset{bag/.style={text centered,yshift=-0.2cm}}
\begin{tikzpicture}[grow=down, -stealth]
    child{ edge from parent node[right]{$\_ DS$}; \node[bag]{$S_1{:}(R_{good})$}
            child{ edge from parent node[right]{and}; \node[bag]{$S_2{:}(and)$}
                    child{ edge from parent node[right=0.1cm]{$[else]$}; \node[bag]{$S_3{:}(A_1)$}
                    child{ edge from parent node[right=0.9cm]{$[if]$}; \node[bag]{$S_4{:}(R_{good})$}


the result is enter image description here however, I want to change the line from s2 to s4 to -|, which I have described in the image using the red line, I tried to use the code child{ edge from parent[-|]node[right=0.9cm]{$[if]$}; \node[bag]{$S_4{:}(R_{good})$}; \node[bag]{$S_3{:}(A_1)$} but it doesn't work would someone help me?

share|improve this question
Why did you choose a tree for this? There are simpler options for this kind of diagram. – Gonzalo Medina Aug 18 '12 at 2:05
@GonzaloMedina sorry, I am not familiar with tikze :( would you give me an simper opiton in details? thanks – sweetyBaby Aug 18 '12 at 2:17
Of course! I've posted an answer. Feel free to ask (in a comment to my answer) if you don't understand something. – Gonzalo Medina Aug 18 '12 at 2:30
up vote 5 down vote accepted

From the image you posted, it seems that a tree is not the most convenient structure to use. In the code below I show another (in my opinion, simpler) option:



  bag/.style={text centered},
\begin{tikzpicture}[node distance=5mm and 20mm,-stealth]
\node[bag] (s0) {$S_0{:}(B,true,0)$};
\node[bag,below =of s0] (s1) {$S_1{:}(R_{good})$};
\node[bag,below =of s1] (s2) {$S_2{:}(and)$};
\node[bag,below =of s2] (s3) {$S_3{:}(A_1)$};
\node[bag,right =of s3] (s4) {$S_4{:}(R_{good})$};
\draw (s0) -- node[aux,auto] {$\_DS$} (s1);
\draw (s1) -- node[aux,auto] {and} (s2);
\draw (s2)  -| node[aux,auto,near start] {$[if]$} (s4);
\draw (s2) -- node[aux,auto] {$[else]$} (s3);


enter image description here

share|improve this answer
thanks for your help. i still have a problem, how to decrease the size of the picture, it seems too large for me to put it in my document? – sweetyBaby Aug 18 '12 at 3:16
I changed the font=8pt, however, it doesn't work – sweetyBaby Aug 18 '12 at 3:21
@sweetyBaby you can use scale=<factor>,transform shape, as in \begin{tikzpicture}[node distance=5mm and 20mm,-stealth,scale=0.7,transform shape]. – Gonzalo Medina Aug 18 '12 at 3:26
thansk :) so what's "aux" used for ? – sweetyBaby Aug 18 '12 at 3:31
From aux/.style={font=\footnotesize}, is a style that defines the font of labels placed near arrows; indeed, you can see that aux is passed in the node option there. – Claudio Fiandrino Aug 18 '12 at 6:53

Your Answer


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.