# how to draw special line in a picture

Here is my current code for the picture:

\documentclass[a4paper,12pt]{article}
\usepackage{tikz}
\usetikzlibrary{trees}

\begin{document}
\resizebox{.5\textwidth}{!}{
\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]
\node[bag]{$S_0{:}(B,true,0)$}
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[missing]
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})$}
}
}
};
\end{tikzpicture}}

\end{document}


the result is 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?

-
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

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:

\documentclass[a4paper,12pt]{article}
\usepackage{tikz}
\usetikzlibrary{positioning}

\begin{document}

\tikzset{
bag/.style={text centered},
aux/.style={font=\footnotesize}
}
\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);
\end{tikzpicture}

\end{document}


-
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