cómo dibujar una línea especial en una imagen

cómo dibujar una línea especial en una imagen

Aquí está mi código actual para la imagen:

\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}

Sin embargo, el resultado es que ingrese la descripción de la imagen aquíquiero cambiar la línea de s2 a s4 a -|, que describí en la imagen usando la línea roja, intenté usar el código child{ edge from parent[-|]node[right=0.9cm]{$[if]$}; \node[bag]{$S_4{:}(R_{good})$}; \node[bag]{$S_3{:}(A_1)$} pero no funciona. ¿Alguien me podría ayudar?

Respuesta1

Por la imagen que publicaste, parece que un árbol no es la estructura más conveniente de usar. En el siguiente código muestro otra opción (en mi opinión, más sencilla):

\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}

ingrese la descripción de la imagen aquí

información relacionada