![在这个 tikz-qtree 上,当我为节点着色时,父节点被覆盖。如何修复?](https://linux22.com/image/334542/%E5%9C%A8%E8%BF%99%E4%B8%AA%20tikz-qtree%20%E4%B8%8A%EF%BC%8C%E5%BD%93%E6%88%91%E4%B8%BA%E8%8A%82%E7%82%B9%E7%9D%80%E8%89%B2%E6%97%B6%EF%BC%8C%E7%88%B6%E8%8A%82%E7%82%B9%E8%A2%AB%E8%A6%86%E7%9B%96%E3%80%82%E5%A6%82%E4%BD%95%E4%BF%AE%E5%A4%8D%EF%BC%9F.png)
\documentclass{article}
\usepackage{tikz}
\usepackage{tikz-qtree}
\usetikzlibrary{trees} % this is to allow the fork right path
\pagecolor{olive!50!yellow!50!white}
\begin{document}
\begin{tikzpicture}[level distance=1.25in,sibling distance=.25in,scale=.75]
\tikzset{edge from parent/.style=
{thick, draw,
edge from parent fork right},every tree node/.style={draw,minimum width=1in,text width=1in, align=center,fill=white},grow'=right}
\Tree
[. parent
[.{nice child0}
[.{grandchild0-0 } ]
[.{grandchild0-1 } ]
[.{grandchild0-2 } ]
[.{grandchild0-3 with a really long name } ]
]
[.child1
[.{grandchild1-0 } ]
[.{grandchild1-1 } ]
[.{grandchild1-2 } ]
]
[.child2 ]
[.child3 ]
]
\begin{scope}
\tikzset{edge from parent/.style=
{thick, draw,
edge from parent fork left},every tree node/.style={draw,minimum width=1in,text width=1in, align=center,fill=white},grow'=left}
\Tree
[.\node[draw=none]{};
[.{nice child0}
[.{grandchild0-0 } ]
[.{grandchild0-1 } ]
[.{grandchild0-2 } ]
[.{grandchild0-3 with a really long name } ]
]
[.child1
[.{grandchild1-0 } ]
[.{grandchild1-1 } ]
[.{grandchild1-2 } ]
]
[.child2 ]
[.child3 ]
]
\end{scope}
\end{tikzpicture}
\end{document}
答案1
这与您如何覆盖树节点有关。请注意,TikZ 绘制第一个节点并设置父节点,然后在其上方绘制;因此,按照您的方式,TikZ 会在标签上方填充绘制和空框。因此,切换绘制顺序可以解决问题。
参见 MWE:
\documentclass{article}
\usepackage{tikz}
\usepackage{tikz-qtree}
\usetikzlibrary{trees} % this is to allow the fork right path
\pagecolor{olive!50!yellow!50!white}
\begin{document}
\begin{tikzpicture}[level distance=1.25in,sibling distance=.25in,scale=.75]
\tikzset{edge from parent/.style=
{thick, draw,
edge from parent fork right},every tree node/.style={draw,minimum width=1in,text width=1in, align=center,fill=white},grow'=right}
\Tree
[.{}
[.{nice child0}
[.{grandchild0-0 } ]
[.{grandchild0-1 } ]
[.{grandchild0-2 } ]
[.{grandchild0-3 with a really long name } ]
]
[.child1
[.{grandchild1-0 } ]
[.{grandchild1-1 } ]
[.{grandchild1-2 } ]
]
[.child2 ]
[.child3 ]
]
\begin{scope}
\tikzset{edge from parent/.style=
{thick, draw,
edge from parent fork left},every tree node/.style={draw,minimum width=1in,text width=1in, align=center,fill=white},grow'=left}
\Tree
[.{parent}
[.{nice child0}
[.{grandchild0-0 } ]
[.{grandchild0-1 } ]
[.{grandchild0-2 } ]
[.{grandchild0-3 with a really long name } ]
]
[.child1
[.{grandchild1-0 } ]
[.{grandchild1-1 } ]
[.{grandchild1-2 } ]
]
[.child2 ]
[.child3 ]
]
\end{scope}
\end{tikzpicture}
\end{document}