![节点结构类似文件系统](https://linux22.com/image/260996/%E8%8A%82%E7%82%B9%E7%BB%93%E6%9E%84%E7%B1%BB%E4%BC%BC%E6%96%87%E4%BB%B6%E7%B3%BB%E7%BB%9F.png)
我想绘制一张反映某些文件结构的图片。下面的代码几乎按预期工作。我需要调整节点之间的连接,使它们不从父节点底部的中心开始,而是从左下角附近开始。
我怎样才能做到这一点?
代码:
\documentclass[11pt, oneside]{article}
\usepackage{tikz} % super package for complex and awesome drawing
\begin{document}
\usetikzlibrary{trees}
\tikzstyle{every node}=[draw=black,thick,anchor=west,inner sep=2pt,minimum size=1pt]
\tikzstyle{selected}=[draw=cyan,fill=cyan!30]
\begin{tikzpicture}[
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 {MainFolder-\{version\}}
child { node [label={[xshift=6.0cm, yshift=-0.58cm, color=gray] Documentation for developers}] {References and Documentation/}
child { node [draw=none] {main.html} }
child { node {reference/}
child { node [draw=none] {...}}
}
child [missing] {}
}
child [missing] {}
child [missing] {}
child [missing] {}
child { node {release/}
child { node [draw=none] {libAwesome.a} }
child { node [draw=none] {libAwesome.dylib} }
};
\end{tikzpicture}
\tikzstyle{every node}=[] % resets borders of tables
\tikzstyle{selected}=[] % resets selected
\end{document}
输出:
理想的:
任何帮助都将受到赞赏。
答案1
你必须设置
- 开始
edge from parent path
parent anchor=south west
(将被保存在\tikzparentanchor
)+ .4cm
向右child anchor
(\tikzchildanchor
) 不需要设置,因为|-
路径运算符会处理这个问题(默认.center
锚点具有相同的是值为.west
);
- 以及增长函数的起点 (
grow via three points
)growth parent anchor=west
- 以及增长函数的结束
every child node/.style={anchor=west}
代码
\documentclass[tikz]{standalone}
\usetikzlibrary{trees,calc}
\begin{document}
\tikzset{
every node/.style={
draw=black,
thick,
anchor=west,
inner sep=2pt,
minimum size=1pt,
}
}
\begin{tikzpicture}[
grow via three points={
one child at (0.8,-0.7) and two children at (0.8,-0.7) and (0.8,-1.4)
},
edge from parent path={
($(\tikzparentnode\tikzparentanchor)+(.4cm,0pt)$) |- (\tikzchildnode\tikzchildanchor)
},
growth parent anchor=west,
parent anchor=south west,% = \tikzparentanchor
% child anchor=west,% = \tikzchildanchor
% every child node/.style={anchor=west}% already in "every node"
]
\node {MainFolder-\{version\}}
child { node [label={[xshift=6.0cm, yshift=-0.58cm, color=gray] Documentation for developers}] {References and Documentation/}
child { node [draw=none] {main.html} }
child { node {reference/}
child { node [draw=none] {\ldots}}
}
child [missing] {}
}
child [missing] {}
child [missing] {}
child [missing] {}
child { node {release/}
child { node [draw=none] {libAwesome.a} }
child { node [draw=none] {libAwesome.dylib} }
};
\end{tikzpicture}
\end{document}