如何畫角度線?

如何畫角度線?

可能的重複:
如何在圖片中繪製特殊的線條

我使用下面的程式碼來繪製圖片,但是參考圖像,該線是從 s2 到 s4 的直線。在此輸入影像描述

但是,我想要像圖中紅線那樣的角度的線。

\usepackage{tikz}
\usetikzlibrary{trees}
\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]{$\lsInvoke \_ 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}} 

答案1

我無法編譯你的程式碼,也沒有任何關於樹的經驗,這似乎為你繪製了路徑。這應該展示我認為您正在尋找的概念:

\documentclass{article}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
    \coordinate (A) at (0,0);
    \coordinate (B) at (5,-1);
    \draw (A) -- (B);
    \draw[thick,dashed,red,->] (A) -| (B);
\end{tikzpicture}
\end{document}

其產生:

結果

這裡對您來說最重要的部分是使用-|而不是--在直線座標係而不是標準座標系中建立路徑。當與繪製一起使用時,不是繪製直線,而是繪製該線的組成部分。

也許您可以在 S_2 和 S_4 處建立命名座標並將直線路徑覆蓋在其上?

相關內容