如何保证上图中红字所在的结点,处在上下相邻的两个cyan小圆点的绝对中间位置?
当更改level distance后,由于红字结点的位置是一个绝对位置(A.south)的绝对偏移量(-.55cm),要保证它处在绝对中间位置,应当使用相对位置,或者说红字所在的结点很有可能是一个预定义的结点。
因太久没看文档,(如果存在,)我忘记了它的名字了。感觉如果能找出来,就可以用两定点的中点语法($(A)!.5!(B)$)
来表示红字结点的位置。重点在于观察这个树状图的连接线是如何在向下后分别向左和向右拐弯。
如果并不存在这样的预定义结点,请问应该如何使之实现?
\documentclass[border=2pt,tikz]{standalone}
\usetikzlibrary{trees}
\tikzset{
every node/.style={draw,inner sep=2pt},
level/.style={level distance=1.5cm},
level 1/.style={sibling distance=4.5cm},
level 2/.style={sibling distance=2cm}
}
\begin{document}
\begin{tikzpicture}
\node (A) {A}
[edge from parent fork down]
child {node {A.1}
child {node {A.1.1}}
child {node {A.1.2}}
}
child {node {A.2}
child {node {A.2.1}}
child {node {A.2.2}}
}
;
\fill [blue]
([yshift=-.275cm]A.south) circle (1pt);
\fill [cyan]
(A.center) circle (1pt)
(A.south) circle (1pt)
([yshift=-.55cm]A.south) circle (1pt);
\node at ([yshift=-.275cm]A.south)
[scale=.375,font=\ttfamily,draw=none,text=red]
{hello};
\end{tikzpicture}
\end{document}
maybe related: https://tex.stackexchange.com/questions/142296/tikz-tree-fork-down-edge-labels
但我看不太懂....
在tikz-ext
库中有很方便的<spec>
:|-|
和-|-
等
\documentclass[border=2pt,tikz]{standalone}
\usetikzlibrary{trees,ext.paths.ortho}
\tikzset{
every node/.style={draw,inner sep=2pt},
level/.style={level distance=1.5cm},
level 1/.style={sibling distance=4.5cm},
level 2/.style={sibling distance=2cm}
}
\begin{document}
\begin{tikzpicture}
\node (A) {A}
[edge from parent fork down]
child {node (A1) {A.1}
child {node {A.1.1}}
child {node {A.1.2}}
}
child {node {A.2}
child {node {A.2.1}}
child {node {A.2.2}}
}
;
\path[magenta,draw] (A1.north) |-| (A.south)
node[pos=.25] {.25}
node[pos=.5] {.5}
node[pos=.75] {.75}
node[pos=.875] {.875}
coordinate[pos=.875] (P)
;
\node[inner sep=0pt,circle,pin=above right:P] at (P) {};
\end{tikzpicture}
\end{document}
问题表述已更新
上面的代码的
P
就是处于「上下相邻的两个cyan小圆点的绝对中间位置」,无论level distance
取什么长度(?)其中「要保证它处在绝对中间位置,应当使用相对位置,或者说红字所在的结点很有可能是一个预定义的结点」这个推断逻辑上 或许 有点问题,「要保证它处在绝对中间位置」是你的需求,而不是
pgf
的需求。pgf
只需要画线,不一定需要关心路径的中间点并且显式给他命名。尝试找了一下源码:
这个「中间结点」在
tikz
内部 似乎 未被显式定义,你或许可以试试仿照上述方式定义my edge from parent fork down
的样式...