我正在关注此链接提供的教程/MWE:http://www.texample.net/tikz/examples/filesystem-tree/
我希望有两个节点位于同一行,例如:
[MAIN]
|__________[UNDERMAIN1]____[PROPERTY1.1]_____[PROPERTY1.2]
|__________[UNDERMAIN2]____[PROPERTY2]
|____________[UNDERUNDERMAIN2]_______[PROPERTY3]
到目前为止,我只找到了在 [undermain] 下方具有 [properties] 的方法,但不在同一行。
预先感谢您的帮助。
答案1
最简单的方法是稍后将属性节点添加到命名节点。
解决方案包括以下键
property direction
,properties
,
和风格
every property
和every property edge
。
树构建完成后,properties
通过 使用late options
。
代码
\documentclass[tikz,convert=false]{standalone}
\usetikzlibrary{trees,positioning}
\makeatletter
\tikzset{
property direction/.initial=mid right,
properties/.style={
append after command={
\pgfextra\let\qrr@tikzlastnode\tikzlastnode\endpgfextra
\foreach \pgf@temp[count=\qrr@tikz@fig@prop from 0] in {#1} {
\pgfextra
\ifnum\qrr@tikz@fig@prop=0
\let\qrr@tikz@fig@suffix\pgfutil@empty
\else
\edef\qrr@tikz@fig@suffix{-\number\numexpr\qrr@tikz@fig@prop-1\relax}%
\fi
\endpgfextra
node [
every property/.try,
\pgfkeysvalueof{/tikz/property direction}=of \qrr@tikzlastnode\qrr@tikz@fig@suffix,
name=\qrr@tikzlastnode-\qrr@tikz@fig@prop] {\pgf@temp}
edge[every property edge/.try] (\qrr@tikzlastnode\qrr@tikz@fig@suffix)
}
}
}
}
\makeatother
\tikzset{
every property/.style={
thin,
node distance=.25cm,
},
every property edge/.style={densely dotted,-}
}
\begin{document}
\begin{tikzpicture}[
every node/.append style={draw=black,thick,anchor=west,text height=\heightof{A}, text depth=+0pt},
selected/.style={draw=red,fill=red!30},
optional/.style={dashed,fill=gray!50},
grow via three points={one child at (0.5,-0.7) and two children at (0.5,-0.7) and (0.5,-1.4)},
edge from parent path={(\tikzparentnode.south) |- (\tikzchildnode.west)}
]
\node (texmf) {texmf}
child { node (doc) {doc} }
child { node {fonts} }
child { node {source}}
child { node [selected] {tex}
child { node {generic}}
child { node [optional] {latex}}
child { node {plain}}
}
child [missing] {}
child [missing] {}
child [missing] {}
child {node {texdoc}};
\path [late options={name=doc,properties={a,b,c}}];
\path [late options={name=texmf-1,properties={d,e,f}}];
\end{tikzpicture}
\end{document}