我正在尝试绘制一棵树,树叶上有一些文字,我想旋转这些文字。下面的代码运行良好,只是树叶的边缘固定在树叶的右侧而不是顶部。
\documentclass{article}
\usepackage{amssymb}
\usepackage{tikz}
\usepackage{tikz-qtree}
\begin{document}
\begin{tikzpicture}
\tikzset{every leaf node/.style={font=\tiny,anchor=base west,rotate=-90}}
\tikzset{edge from parent/.style=
{draw,
edge from parent path={(\tikzparentnode.south)
-- +(0,-8pt)
-| (\tikzchildnode)}}}
\Tree [.{$\rightarrow$}
[.{$\land$}
[.{$\circlearrowleft$} {$\tau$} {CRP} ]
[.{$\rightarrow$}
[.{$\land$}
[.{$\circlearrowleft$} {$\tau$} {Leucocytes} ]
[.{$\circlearrowleft$} {$\tau$} {IV Antibiotics} {IV Liquid} {ER Registration} {Admission IC} {Admission NC} {LacticAcid} {ER Triage} {ER Sepsis Triage} ]
]
[.{$\times$} {Release A} {$\tau$} ]
]
]
[.{$\times$} {Release C} {Release B}
[.{$\rightarrow$}
[.{$\times$} {Release E} {Release D} {$\tau$} ]
{Return ER}
]
{$\tau$}
]
]
\end{tikzpicture}
\end{document}
其呈现形式为:
如何将边缘固定到叶子顶部?
请注意,通过改变
\tikzset{edge from parent/.style=
{draw,
edge from parent path={(\tikzparentnode.south)
-- +(0,-8pt)
-| (\tikzchildnode)}}}
到
\tikzset{edge from parent/.style=
{draw,
edge from parent path={(\tikzparentnode.south)
-- +(0,-8pt)
-| (\tikzchildnode.west)}}}
中间节点之间的边锚定在子节点的左侧。这是不受欢迎的。
答案1
tikz-qtree
非常不灵活,所以我们需要一个既适用于未旋转节点又适用于旋转节点的锚点。我没有.north
对其中一个节点使用锚点,而是对两个节点都使用锚点,并将其水平投影以对齐- 即:.west
.north west
.center
(\tikzchildnode.north west -| \tikzchildnode.center)
\documentclass[tikz, border=1 cm]{standalone}
\usepackage{amssymb}
\usepackage{tikz}
\usepackage{tikz-qtree}
\begin{document}
\begin{tikzpicture}
\tikzset{every leaf node/.style={font=\tiny,anchor=base west,rotate=-90}}
\tikzset{edge from parent/.style=
{draw,
edge from parent path={(\tikzparentnode.south)
-- +(0,-8pt)
-| (\tikzchildnode.north west -| \tikzchildnode.center)}}}
\Tree [.{$\rightarrow$}
[.{$\land$}
[.{$\circlearrowleft$} {$\tau$} {CRP} ]
[.{$\rightarrow$}
[.{$\land$}
[.{$\circlearrowleft$} {$\tau$} {Leucocytes} ]
[.{$\circlearrowleft$} {$\tau$} {IV Antibiotics} {IV Liquid} {ER Registration} {Admission IC} {Admission NC} {LacticAcid} {ER Triage} {ER Sepsis Triage} ]
]
[.{$\times$} {Release A} {$\tau$} ]
]
]
[.{$\times$} {Release C} {Release B}
[.{$\rightarrow$}
[.{$\times$} {Release E} {Release D} {$\tau$} ]
{Return ER}
]
{$\tau$}
]
]
\end{tikzpicture}
\end{document}