答案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 之前的版本中存在错误。您仍然可以这样做,但更新比解决错误要容易得多。如果您的树没有唯一的子节点,这不是问题,但如果您有其他树,则可能是问题。出于类似的原因,对齐边缘也不容易。您需要做一些事情才能使其正常工作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}