# How to make a connection in a tree with a dashed line?

please refer to the answer of how to draw a process flow figure?

Now I want to change the line of "and->path1" to the dashed line, i added [style=dashed], unfortunately it doesn't change, why?

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

\tikzset{level 1/.style={level distance=1.5cm, sibling distance=3.5cm}}
\tikzset{level 2/.style={level distance=1.5cm, sibling distance=2cm}}

\tikzset{bag/.style={text width=20em, text centered,yshift=-0.2cm}}

\begin{document}
\begin{tikzpicture}[grow=down, -stealth]
\node[bag]{$(B)$}
child{ edge from parent node[right]{t}; \node[bag]{$(Rgood)$}
child{ edge from parent node[right]{and}; \node[bag]{$(and)$}
child[missing]
child{ edge from parent node[right=0.1cm][style =dashed]{it}; \node[bag]{$(path1)$}}
child{ edge from parent node[right=0.1cm]{else}; \node[bag]{$(path2)$}}
}
};
\end{tikzpicture}

\end{document}

-

It is possible to locally define a style introducing the option near the keyword child.

The example, therefore, should become:

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

\tikzset{level 1/.style={level distance=1.5cm, sibling distance=3.5cm}}
\tikzset{level 2/.style={level distance=1.5cm, sibling distance=2cm}}

\tikzset{bag/.style={text width=20em, text centered,yshift=-0.2cm}}

\begin{document}
\begin{tikzpicture}[grow=down, -stealth]
\node[bag]{$(B)$}
child{ edge from parent node[right]{t}; \node[bag]{$(Rgood)$}
child{ edge from parent node[right]{and}; \node[bag]{$(and)$}
child[missing]
child[dashed]{ edge from parent node[right=0.1cm]{it}; \node[bag]{$(path1)$}}  % <= NOTICE the dashed near child
child{ edge from parent node[right=0.1cm]{else}; \node[bag]{$(path2)$}}
}
};
\end{tikzpicture}
\end{document}


The result is:

For completeness, let see what happens playing with the position of options.

In the previous example, assume each time to just change the line:

child[dashed]{ edge from parent node[right=0.1cm]{it}; \node[bag]{$(path1)$}}


1. Insert a color definition inside the node option.

child[dashed]{ edge from parent node[right=0.1cm,red]{it}; \node[bag]{$(path1)$}}


The result is:

2. Let's now shift the color definition by inserting it as option of edge from parent.

child[dashed]{ edge from parent[red] node[right=0.1cm]{it}; \node[bag]{$(path1)$}}


This gives:

Although it seems the identical previous result, actually the connection is first drawn in red, then the style is override by the child definition in black. The label still remains in black.

3. Let's now shift the color definition by inserting it as option of child.

child[dashed,red]{ edge from parent node[right=0.1cm]{it}; \node[bag]{$(path1)$}}


This gives:

Once the option is put in this position, it holds for all elements.

EDIT

Now I want to change the line of "and->path1" to the dashed line, i added [style=dashed], unfortunately it doesn't change, why?

not:

so is there any way to make the line bettween "(Rgood)->(and)" dashed while the line between "(and)->path1" remains the same, that is to say, not dashed？

A workaround for that is:

\documentclass[a4paper,12pt]{article}
\usepackage[width=15cm]{geometry}
\usepackage{pgfplots}
\usetikzlibrary{trees}

\tikzset{level 1/.style={level distance=1.5cm, sibling distance=3.5cm}}
\tikzset{level 2/.style={level distance=1.5cm, sibling distance=2cm}}

\tikzset{bag/.style={text width=20em, text centered,yshift=-0.2cm}}

\begin{document}
\scalebox{1.5}{
\begin{tikzpicture}[grow=down, -stealth,dashed]
\node[bag]{$(B)$}
child{ edge from parent[solid] node[right]{t}; \node[bag]{$(Rgood)$}
child{ edge from parent node[right]{and}; \node[bag]{$(and)$}
child[missing]
child{ edge from parent[solid] node[right=0.1cm]{it}; \node[bag]{$(path1)$}}
child{ edge from parent[solid] node[right=0.1cm]{else}; \node[bag]{$(path2)$}}
}
};
\end{tikzpicture}
}

\end{document}

-
thanks,however, I just only one line to be dashed.If I use this method, all children's line are all dashed. For example, if I use this method to make "Rgood->and" to be dashed, then the “and ->path1” also be dashed authomatically, however, I just want to change "Rgood->and" dashed, "and->path1" remains the line. why? –  sweetyBaby Aug 14 '12 at 7:23
Perhaps my edit will answer you. :) –  Claudio Fiandrino Aug 14 '12 at 7:37
thanks for your detailed explaination, so is there any way to make the line bettween "(Rgood)->(and)" dashed while the line between "(and)->path1" remains the same, that is to say, not dashed？ I try it in this way child{ edge from parent [dashed] node... it doesn't work –  sweetyBaby Aug 14 '12 at 8:00