我想将一棵丑陋的树重新创建为漂亮的 TikZ 图形树。但是这棵树有点复杂,我需要帮助。
然而我被这两个问题困扰着
我需要通过延长线路将某些内容从 3 级“孙子”移到 6 级“3 代后的孙子”。
我有一些孩子在中间,他们将形成我的人物称之为“超级棘手”的东西。它基本上介于 5 级和 6 级之间,很多孩子都会进入这个阶段。我把线画成红色,以吸引你关注这个问题。它基本上是关闭松散的末端。(我的意思是这显然不是家谱:D)图片有帮助。
这是我目前所拥有的:
\documentclass[border=3pt]{standalone}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}[sibling distance=10em,
every node/.style = {shape=rectangle, rounded corners, draw, align=left}]]
\node { I am fine with this}
child { node {Top level \\ outside tree}}
child { node {Top level \\ inside tree}
child { node {Level 1 \\ right}
child { node {Level 2 \\ right }
child {node { Lowest in \\Left}}}}
child { node {level 1 \\ middle}
child { node {Level 2 \\ middle}
child {node { lowest in \\middle}}}}
child { node {level 1 \\ right}
child { node {Level 2 \\ right left}
child {node {Level 3 \\ right left}}}
child { node {Level 2 \\ right right}
child {node {Level 3 \\ right right}
child{node{Level 4 \\ right left}}
child{node{Level 4 \\ right right}
child{node {Level 5 \\ right left}
child{node{Lowest in \\right}} } } }} } } ;
\end{tikzpicture}
\end{document}
抱歉图片太丑了,谢谢你的帮助!
答案1
所以我尝试使用和tikz
。我不熟悉,所以这是我的解决方案,也许你会得到一些与 相关的答案。nodes
calc
trees
trees
\documentclass{standalone}
\usepackage{makecell}
\usepackage{tikz}
\usetikzlibrary{calc}
\tikzset{%
every node/.style={minimum width=2cm, minimum height=1cm, fill=blue!75!black},
}
\begin{document}
\begin{tikzpicture}
%nodes
%level 0
\node at (0,0) (lv0a) {\textcolor{white}{\makecell[c]{Level \# \\ position}}};
\node[anchor=west] at ($(lv0a.east) + (4,0)$) (lv0b) {\textcolor{white}{\makecell[c]{Level \# \\ position}}};
%level 1
\node[anchor=north west] at ($(lv0b.south east) + (2,-1)$) (lv1a) {\textcolor{white}{\makecell[c]{Level \# \\ position}}};
\node[anchor=north] at ($(lv0b.south) + (0,-1) $) (lv1b) {\textcolor{white}{\makecell[c]{Level \# \\ position}}};
\node[anchor=north east] at ($(lv0b.south west) + (-2,-1)$) (lv1c) {\textcolor{white}{\makecell[c]{Level \# \\ position}}};
%level 2
\node[anchor=north west] at ($(lv1a.south) + (0.5,-1)$) (lv2a) {\textcolor{white}{\makecell[c]{Level \# \\ position}}};
\node[anchor=north east] at ($(lv1a.south) + (-0.5,-1)$) (lv2b) {\textcolor{white}{\makecell[c]{Level \# \\ position}}};
\node[anchor=north] at ($(lv1b.south) + (0,-1)$) (lv2c) {\textcolor{white}{\makecell[c]{Level \# \\ position}}};
\node[anchor=north] at ($(lv1c.south) + (0,-1)$) (lv2d) {\textcolor{white}{\makecell[c]{Level \# \\ position}}};
%level 3
\node[anchor=north] at ($(lv2a.south) + (0,-1)$) (lv3a) {\textcolor{white}{\makecell[c]{Level \# \\ position}}};
\node[anchor=north] at ($(lv2b.south) + (0.5,-1)$) (lv3b) {\textcolor{white}{\makecell[c]{Level \# \\ position}}};
% level 4
\node[anchor=north west] at ($(lv3a.south) + (0.5,-1)$) (lv4a) {\textcolor{white}{\makecell[c]{Level \# \\ position}}};
\node[anchor=north east] at ($(lv3a.south) + (-0.5,-1)$) (lv4b) {\textcolor{white}{\makecell[c]{Level \# \\ position}}};
% level 5
\node[anchor=north west] at ($(lv4a.south) + (0.5,-1)$) (lv5a) {\textcolor{white}{\makecell[c]{Level \# \\ position}}};
\node[anchor=north east] at ($(lv4a.south) + (-0.5,-1)$) (lv5b) {\textcolor{white}{\makecell[c]{Level \# \\ position}}};
\node[anchor=east] at ($(lv5b.west) + (-5.5,0)$) (lv5c) {\textcolor{white}{\makecell[c]{Level \# \\ super tricky}}};
% level 6
\node[anchor=north] at ($(lv5a.south) + (0.5,-1)$) (lv6a) {\textcolor{white}{\makecell[c]{Level \# \\ position}}};
\node[anchor=east] at ($(lv6a.west) + (-6.5,0)$) (lv6b) {\textcolor{white}{\makecell[c]{Level \# \\ position}}};
\node[anchor=east] at ($(lv6b.west) + (-2,0)$) (lv6c) {\textcolor{white}{\makecell[c]{Level \# \\ position}}};
%lines
%level0
\draw[blue!75!black] (3,1.5) --++ (0,-0.5) -| (lv0a.north);
\draw[blue!75!black] (3,1.5) --++ (0,-0.5) -| (lv0b.north);
%level1
\draw[blue!75!black] (lv0b.south) --++ (0,-0.5) -| (lv1a.north);
\draw[blue!75!black] (lv0b.south) -- (lv1b.north);
\draw[blue!75!black] (lv0b.south) --++ (0,-0.5) -| (lv1c.north);
%level2
\draw[blue!75!black] (lv1a.south) --++ (0,-0.5) -| (lv2a.north);
\draw[blue!75!black] (lv1a.south) --++ (0,-0.5) -| (lv2b.north);
\draw[blue!75!black] (lv1b.south) -- (lv2c.north);
\draw[blue!75!black] (lv1c.south) -- (lv2d.north);
%level3
\draw[blue!75!black] (lv2a.south) --(lv3a.north);
\draw[blue!75!black] ($(lv2b.south west) + (0.25,0)$) |- (lv3b.west);
\draw[blue!75!black] ($(lv2c.south west) + (0.25,0)$) |- (lv6b.west);
\draw[blue!75!black] ($(lv2d.south west) + (0.25,0)$) |- (lv6c.west);
%level4
\draw[blue!75!black] (lv3a.south) --++ (0,-0.5) -| (lv4a.north);
\draw[blue!75!black] (lv3a.south) --++ (0,-0.5) -| (lv4b.north);
%level5
\draw[blue!75!black] (lv4a.south) --++ (0,-0.5) -| (lv5a.north);
\draw[blue!75!black] (lv4a.south) --++ (0,-0.5) -| (lv5b.north);
%super tricky
\draw[red!75!black] (lv5c.north) |- (lv3b.west);
\draw[red!75!black] (lv5c.north) |- (lv4b.west);
\draw[red!75!black] (lv5c.east) |- (lv5b.west);
\draw[red!75!black] (lv5c.east) -| (lv6b.north);
\draw[red!75!black] (lv5c.west) -| (lv6c.north);
% level6
\draw[blue!75!black] ($(lv5a.south west) + (0.25,0)$) |- (lv6a.west);
\end{tikzpicture}
\end{document}
如果它适合您的需要并且您需要进行一些调整,请在评论中告诉我。
编辑
关于你的问题:这符合你的目的吗?
\documentclass{standalone}
\usepackage{makecell}
\usepackage{pgfplots}
\usetikzlibrary{calc}
\tikzset{%
every node/.style={minimum width=2cm, minimum height=1cm, draw=blue!50!black, fill=blue!75!black},
}
\begin{document}
\begin{tikzpicture}
%nodes
%start
\node at (0,0) (start) {\textcolor{white}{\makecell[c]{start \\ position}}};
%level 0
\node[anchor=north] at ($(start.south) + (-2,-1) $) (lv0a) {\textcolor{white}{\makecell[c]{Level \# \\ position}}};
\node[anchor=north] at ($(start.south) + (2,-1)$) (lv0b) {\textcolor{white}{\makecell[c]{Level \# \\ position}}};
%level 1
\node[anchor=north west] at ($(lv0b.south east) + (2,-1)$) (lv1a) {\textcolor{white}{\makecell[c]{Level \# \\ position}}};
\node[anchor=north] at ($(lv0b.south) + (0,-1) $) (lv1b) {\textcolor{white}{\makecell[c]{Level \# \\ position}}};
\node[anchor=north east] at ($(lv0b.south west) + (-2,-1)$) (lv1c) {\textcolor{white}{\makecell[c]{Level \# \\ position}}};
%level 2
\node[anchor=north west] at ($(lv1a.south) + (0.5,-1)$) (lv2a) {\textcolor{white}{\makecell[c]{Level \# \\ position}}};
\node[anchor=north east] at ($(lv1a.south) + (-0.5,-1)$) (lv2b) {\textcolor{white}{\makecell[c]{Level \# \\ position}}};
\node[anchor=north] at ($(lv1b.south) + (0,-1)$) (lv2c) {\textcolor{white}{\makecell[c]{Level \# \\ position}}};
\node[anchor=north] at ($(lv1c.south) + (0,-1)$) (lv2d) {\textcolor{white}{\makecell[c]{Level \# \\ position}}};
%level 3
\node[anchor=north] at ($(lv2a.south) + (0,-1)$) (lv3a) {\textcolor{white}{\makecell[c]{Level \# \\ position}}};
\node[anchor=north] at ($(lv2b.south) + (0,-1)$) (lv3b) {\textcolor{white}{\makecell[c]{Level \# \\ position}}};
% level 4
\node[anchor=north west] at ($(lv3a.south) + (0.5,-1)$) (lv4a) {\textcolor{white}{\makecell[c]{Level \# \\ position}}};
\node[anchor=north east] at ($(lv3a.south) + (-0.5,-1)$) (lv4b) {\textcolor{white}{\makecell[c]{Level \# \\ position}}};
% level 5
\node[anchor=north west] at ($(lv4a.south) + (0.5,-1)$) (lv5a) {\textcolor{white}{\makecell[c]{Level \# \\ position}}};
\node[anchor=north east] at ($(lv4a.south) + (-0.5,-1)$) (lv5b) {\textcolor{white}{\makecell[c]{Level \# \\ position}}};
\node[anchor=center] at (start.south |- lv5b) (lv5c) {\textcolor{white}{\makecell[c]{Level \# \\ super tricky}}};
% level 6
\node[anchor=north] at ($(lv5a.south) + (0,-1)$) (lv6a) {\textcolor{white}{\makecell[c]{Level \# \\ position}}};
\node[anchor=center] at (lv2c.south |- lv6a.west) (lv6b) {\textcolor{white}{\makecell[c]{Level \# \\ position}}};
\node[anchor=center] at (lv2d.south |- lv6a.west) (lv6c) {\textcolor{white}{\makecell[c]{Level \# \\ position}}};
%lines
%level0
\draw[blue!75!black] (start.south) --++ (0,-0.5) -| (lv0a.north);
\draw[blue!75!black] (start.south) --++ (0,-0.5) -| (lv0b.north);
%level1
\draw[blue!75!black] (lv0b.south) --++ (0,-0.5) -| (lv1a.north);
\draw[blue!75!black] (lv0b.south) -- (lv1b.north);
\draw[blue!75!black] (lv0b.south) --++ (0,-0.5) -| (lv1c.north);
%level2
\draw[blue!75!black] (lv1a.south) --++ (0,-0.5) -| (lv2a.north);
\draw[blue!75!black] (lv1a.south) --++ (0,-0.5) -| (lv2b.north);
\draw[blue!75!black] (lv1b.south) -- (lv2c.north);
\draw[blue!75!black] (lv1c.south) -- (lv2d.north);
%level3
\draw[blue!75!black] (lv2a.south) -- (lv3a.north);
\draw[blue!75!black] (lv2b.south) -- (lv3b.north);
\draw[blue!75!black] (lv2c.south) -- (lv6b.north);
\draw[blue!75!black] (lv2d.south) -- (lv6c.north);
%level4
\draw[blue!75!black] (lv3a.south) --++ (0,-0.5) -| (lv4a.north);
\draw[blue!75!black] (lv3a.south) --++ (0,-0.5) -| (lv4b.north);
%level5
\draw[blue!75!black] (lv4a.south) --++ (0,-0.5) -| (lv5a.north);
\draw[blue!75!black] (lv4a.south) --++ (0,-0.5) -| (lv5b.north);
%super tricky
\draw[red!75!black] (lv5c.north) |- (lv3b.west);
\draw[red!75!black] (lv5c.north) |- (lv4b.west);
\draw[red!75!black] (lv5c.east) |- (lv5b.west);
\draw[red!75!black] (lv5c.east) -| (lv6b.north);
\draw[red!75!black] (lv5c.west) -| (lv6c.north);
% level6
\draw[blue!75!black] (lv5a.south) -- (lv6a.north);
\end{tikzpicture}
\end{document}