
Hier ist mein aktueller Code für das Bild:
\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}
das Ergebnis ist jedoch, dass ich die Zeile von s2 nach s4 in -| ändern möchte, was ich im Bild mithilfe der roten Linie beschrieben habe. Ich habe versucht, den Code zu verwenden,
child{ edge from parent[-|]node[right=0.9cm]{$[if]$}; \node[bag]{$S_4{:}(R_{good})$}; \node[bag]{$S_3{:}(A_1)$}
aber er funktioniert nicht. Kann mir jemand helfen?
Antwort1
Aus dem Bild, das Sie gepostet haben, geht hervor, dass ein Baum nicht die bequemste Struktur ist. Im folgenden Code zeige ich eine andere (meiner Meinung nach einfachere) 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}