
答案1
艾倫的回答工作正常,但對於當前版本的 Forest 來說,無需edge path
從頭開始定義。相反,我們可以使用edges
帶有選項的庫forked edges
。此外,我們可以消除它growth parent anchor=east
,因為它不做任何事情(即使在舊版本的 Forest 中),並且我們可以使用parent
和children
錨點而不是east
和west
來使程式碼更加靈活。
parent anchor=children,
child anchor=parent,
forked edges,
edge={->,>=latex},
事實上,grow=east
它本身就足夠了,所以我們可以完全放棄parent anchor
規格child anchor
。
這為我們提供了以下程式碼,其輸出與艾倫在他的答案中顯示的相同。
\documentclass[tikz,multi,border=10pt]{standalone}
\usepackage[edges]{forest}
\begin{document}
\begin{forest}
for tree={
grow=east,
math content,
edge={->,>=latex},
},
forked edges
[\tau>\tau^0
[A_x<\tau<A_l
]
[D
[E]
[F]
]
[\tau<A_x
[{\zeta^n=\zeta^n-1}
]
]
]
\end{forest}
\end{document}
然而,仔細檢查後,這些線條可能會更好:
預設定義forked edges
是
forked edges/.style={
for tree={parent anchor=children},
for descendants={child anchor=parent,forked edge}
},
因此,讓我們嘗試重新定義它,以便forked edge
僅在節點具有多個子節點時透過新增以下重新定義來使用 :
\forestset{
forked edges/.style={
for tree={parent anchor=children},
for descendants={
child anchor=parent,
if={n_children("!u")==1}{}{
forked edge
},
}
},
}
這個更好:
然而,箭頭仍然是有角度的——它並不完全水平。我們需要做的是edge path
為只有一個孩子的情況定義一種替代方案。
預設邊是從父點的父錨點繪製(!u.parent anchor)
到子節點的子錨點(.child anchor)
。我們希望箭頭的起點與 水平對齊(.child anchor)
。 (當然,我們可以將終點與父級的父錨點對齊。)
\forestset{
forked edges/.style={
for tree={parent anchor=children},
for descendants={
child anchor=parent,
if={n_children("!u")==1}{
edge path'={
(!u.parent anchor |- .child anchor) -- (.child anchor)
},
}{
forked edge,
},
}
},
}
這會產生我們正在尋找的水平箭頭:
然而,這可能不是最好的解決方案。如果父節點和子節點的大小差異太大,我們可能會得到奇怪的對齊方式。因此,也許我們應該告訴 Forest 將子級與父級對齊,以便子級的子錨點與父級的父級錨點對齊。
\forestset{
forked edges/.style={
for tree={parent anchor=children},
for descendants={
child anchor=parent,
if={n_children("!u")==1}{
!u.calign=child edge,
}{
forked edge,
},
}
},
}
就可以了。
現在,結果如下所示:
這更好,但是當父級有奇數個子級時,如果我們可以將中間子級與父級對齊,那就太好了。例如,如果D
的邊緣與從根節點繪製的線對齊。
這有點棘手,但也不是那麼難。我們可以calign=child edge
再次使用這個技巧,將中間的孩子設定為其父母的「主要」孩子。
我們可以將其添加到環境開頭的序言中forest
:
\begin{forest}
for tree={
...
if={isodd(n_children())}{
calign primary child/.pgfmath={(n_children()+1)/2},
calign=child edge,
}{},
},
事實上,由於任何恰好有 1 個子節點的節點都有奇數個子節點,因此我們也可以放棄 的重新定義,forked edges
因為無論如何我們現在都會得到一個直箭頭:
\documentclass[tikz,multi,border=10pt]{standalone}
\usepackage[edges]{forest}
\begin{document}
\begin{forest}
for tree={
grow=east,
math content,
edge={->,>=latex},
if={isodd(n_children())}{
calign primary child/.pgfmath={(n_children()+1)/2},
calign=child edge,
}{}
},
forked edges
[\tau>\tau^0
[A_x<\tau<A_l
]
[D
[E]
[F]
]
[\tau<A_x
[{\zeta^n=\zeta^n-1}
]
]
]
\end{forest}
\end{document}
無恥地竊取希臘代碼馬可:
\begin{forest}
for tree={
grow'=east,
math content,
edge={->,>=latex},
if={isodd(n_children())}{
calign primary child/.pgfmath={(n_children()+1)/2},
calign=child edge,
}{}
},
forked edges
[\tau>\tau^0
[\tau<A_x
[{\zeta^n=\zeta^{n-1}}]
[{\zeta^n=\zeta^{n-1}}]
[{\zeta^n=\zeta^{n-1}}]
]
[A_x<\tau<A_l
[\sigma<C_{a}(T-A_{x})
[{\zeta^n=\zeta^{n-1}}]
[{\zeta^n=\zeta^{n-1}}]
[{\zeta^n=\zeta^{n-1}}]
]
[\sigma>C_{a}(T-A_{x})
[{\xi^{n}=\frac{\xi^{0}}{2}\cos \left ( a_{A}\left (\Gamma-A_{x}-\frac{\sigma}{C_{a}} \right ) \right )}]
[{\xi_{s}^{n}=\xi_{s}^{n}-\frac{\xi_{s}^{n}}{\xi_{s}^{n}}-(\xi^{0}-\xi^{n})}]
[{\xi_{s}^{n}=\xi_{s}^{n}-\frac{\xi_{s}^{n}}{\xi_{s}^{n}}-(\xi^{0}-\xi^{n})}]
]
]
]
\end{forest}
編輯
您的程式碼會產生“間隙”,因為[[<something>]]
會產生一個空節點,然後產生一個帶有[<something>]
.要消除空節點,只需說[<something>]
。
\documentclass{article}
\usepackage{forest-1}
\begin{document}
\begin{forest}
for tree={
grow=east,
parent anchor=east,
child anchor=west,
math content,
edge={->, >={latex}},
edge path={\noexpand\path[\forestoption{edge}] (!u.parent anchor) -- +(5pt,0pt) |- (.child anchor) \forestoption{edge label};}
}
[T>T^0
[T>A_f
[C_a(T-A_f) <\sigma <C_a (T-A_s)
[ {\zeta_s^n=\zeta_s^0-\frac{\zeta_s^0}{\zeta^0}(\zeta^0-\zeta^n)} ]
[ {\zeta_T^n=\zeta_T^0-\frac{\zeta_T^0}{\zeta^0}(\zeta^0-\zeta^n)} ]
[{\zeta^n=\frac{\zeta^0}{2}(cos \big (\alpha_A(T-A_s-\frac{\sigma}{C_a})\big )+1)} ]
]
[\sigma<C_a(T-A_s)
[ {\zeta^n=\zeta^{n-1}} ]
[ {\zeta_s^n=\zeta_s^{n-1}} ]
[ {\zeta_T^n=\zeta_T^{n-1}} ]
]
]
[A_s<T<A_f
[\sigma<C_a(T-A_s)
[ {\zeta_s^n=\zeta_s^0-\frac{\zeta_s^0}{\zeta^0}(\zeta^0-\zeta^n)} ]
[ {\zeta_T^n=\zeta_T^0-\frac{\zeta_T^0}{\zeta^0}(\zeta^0-\zeta^n)} ]
[{\zeta^n=\frac{\zeta^0}{2}(cos \big (\alpha_A(T-A_s-\frac{\sigma}{C_a})\big )+1)}]
[\sigma>C_a(T-A_s)
[ {\zeta^n=\zeta^{n-1}} ]
[ {\zeta_s^n=\zeta_s^{n-1}} ]
[ {\zeta_T^n=\zeta_T^{n-1}} ]
]
]
]
[T<A_s
[ {\zeta^n=\zeta^{n-1}} ]
[ {\zeta_s^n=\zeta_s^{n-1}} ]
[ {\zeta_T^n=\zeta_T^{n-1}} ]
]
]
\end{forest}
\end{document}
請注意,對於版本 1,您做需要指定parent anchor=east, child anchor=west
並更改edge path
。沒有forked edges
。另外,當只有一個孩子時,要消除這種扭結並不容易,因為calign=child edge
在 2.01 之前的版本中存在 bug。您仍然可以這樣做,但更新比解決錯誤要容易得多。如果您的樹沒有唯一的子樹,這不是問題,但如果您有其他樹,則可能會出現問題。由於類似的原因,對齊邊緣也不容易。您需要做一些事情才能edge path
使其正常工作。
另一方面,使用當前的套件,您的樹可以輕鬆調整為如下所示,並且程式碼也更簡單:
\documentclass{article}
\usepackage[edges]{forest}
\begin{document}
\begin{forest}
for tree={
grow'=east,
math content,
edge={->,>=latex},
if={isodd(n_children())}{
calign primary child/.pgfmath={(n_children()+1)/2},
calign=child edge,
}{}
},
forked edges
[T>T^0
[T>A_f
[C_a(T-A_f) <\sigma <C_a (T-A_s)
[ {\zeta_s^n=\zeta_s^0-\frac{\zeta_s^0}{\zeta^0}(\zeta^0-\zeta^n)} ]
[ {\zeta_T^n=\zeta_T^0-\frac{\zeta_T^0}{\zeta^0}(\zeta^0-\zeta^n)} ]
[{\zeta^n=\frac{\zeta^0}{2}(cos \big (\alpha_A(T-A_s-\frac{\sigma}{C_a})\big )+1)} ]
]
[\sigma<C_a(T-A_s)
[ {\zeta^n=\zeta^{n-1}} ]
[ {\zeta_s^n=\zeta_s^{n-1}} ]
[ {\zeta_T^n=\zeta_T^{n-1}} ]
]
]
[A_s<T<A_f
[\sigma<C_a(T-A_s)
[ {\zeta_s^n=\zeta_s^0-\frac{\zeta_s^0}{\zeta^0}(\zeta^0-\zeta^n)} ]
[ {\zeta_T^n=\zeta_T^0-\frac{\zeta_T^0}{\zeta^0}(\zeta^0-\zeta^n)} ]
[{\zeta^n=\frac{\zeta^0}{2}(cos \big (\alpha_A(T-A_s-\frac{\sigma}{C_a})\big )+1)}, calign with current]
[\sigma>C_a(T-A_s)
[ {\zeta^n=\zeta^{n-1}} ]
[ {\zeta_s^n=\zeta_s^{n-1}} ]
[ {\zeta_T^n=\zeta_T^{n-1}} ]
]
]
]
[T<A_s
[ {\zeta^n=\zeta^{n-1}} ]
[ {\zeta_s^n=\zeta_s^{n-1}} ]
[ {\zeta_T^n=\zeta_T^{n-1}} ]
]
]
\end{forest}
\end{document}
答案2
這並不是很難做到的forest
。下面的範例應該可以幫助您入門。
\documentclass{article}
\usepackage{forest}
\begin{document}
\begin{forest}for tree={
grow=east
parent anchor=east,
child anchor=west,
math content,
edge path={\noexpand\path[\forestoption{edge},->, >={latex}]
(!u.parent anchor) -- +(5pt,0pt) |- (.child anchor)
\forestoption{edge label};}}
[\tau>\tau^0 [A_x<\tau<A_l ] [D [E ] [F ]][\tau<A_x [ {\zeta^n=\zeta^n-1} ]]]
\end{forest}
\end{document}
答案3
考慮到這根本不是正確的方法,但我不是專家,這是我知道的唯一方法。
\documentclass[border=0.5cm]{standalone}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
% \draw [help lines] (0,0) grid (13,13);
\draw [thick] (0,0) -- (0,10);
\draw [thick,-latex] (0,5) -- + (0.5,0) node [right] {$A<T<A_{f}$};
\draw [thick,-latex] (2.8,5) -- + (0.5,0);
\draw [thick] (3.3,3.5) -- (3.3,6.5);
\draw [thick,-latex] (3.3,3.5) -- + (0.5,0) node [right] {$\sigma<C_{a}(T-A_{x})$};
\draw [thick,-latex] (3.3,6.5) -- + (0.5,0) node [right] {$\sigma>C_{a}(T-A_{x})$};
\draw [thick,-latex] (0,10) -- + (0.5,0) node [right] {$T<A$};
\draw [thick,-latex] (1.8,10) -- + + (0.5,0);
\draw [thick] (2.3,9) -- (2.3,11);
\draw [thick,-latex] (2.3,9) -- + (0.5,0) node [right] {$\xi^{n}=\xi^{n-1}$};
\draw [thick,-latex] (2.3,10) -- + (0.5,0) node [right] {$\xi^{n}=\xi^{n-1}$};
\draw [thick,-latex] (2.3,11) -- + (0.5,0) node [right] {$\xi_{T}^{n}=\xi_{T}^{n-1}$};
\draw [thick,-latex] (6.5,6.5) -- + (0.5,0);
\draw [thick] (7,5.8) -- + (0,1.4);
\draw [thick,-latex] (7,5.8) -- + (0.5,0) node [right] {$\xi^{n}=\xi^{n-1}$};
\draw [thick,-latex] (7,6.5) -- + (0.5,0) node [right] {$\xi^{n}=\xi^{n-1}$};
\draw [thick,-latex] (7,7.2) -- + (0.5,0) node [right] {$\xi_{T}^{n}=\xi_{T}^{n-1}$};
\draw [thick,-latex] (6.5,3.5) -- + (0.5,0);
\draw [thick] (7,2.5) -- + (0,2);
\draw [thick,-latex] (7,2.5) -- + (0.5,0) node [right] {$\xi^{n}=\frac{\xi^{0}}{2}\cos \left ( a_{A}\left (\Gamma-A_{x}-\frac{\sigma}{C_{a}} \right ) \right )$};
\draw [thick,-latex] (7,3.5) -- + (0.5,0) node [right] {$\xi_{s}^{n}=\xi_{s}^{n}-\frac{\xi_{s}^{n}}{\xi_{s}^{n}}-(\xi^{0}-\xi^{n})$};
\draw [thick,-latex] (7,4.5) -- + (0.5,0) node [right] {$\xi_{s}^{n}=\xi_{s}^{n}-\frac{\xi_{s}^{n}}{\xi_{s}^{n}}-(\xi^{0}-\xi^{n})$};
\end{tikzpicture}
\end{document}