我正在使用tikz-qtree
绘制层次树。但是,树的位置超出了页面。你能帮我将树调整到页面中心吗?谢谢
我当前的代码手动设置为
\documentclass{article}
\usepackage{tikz-qtree}
% command to ensure the line connecting a marriage is centred
% change the rule command as needed; the width of the centre
% column should match the width of the rule
\newcommand*{\marriage}[2]{
\begin{tabular}{>{\raggedleft}p{.5in}@{}>{\centering}p{.2in}@{}>{}p{.5in}}%
#1 & \rule[3pt]{.2in}{\pgflinewidth} & #2
\end{tabular}}
\begin{document}
\tikzset{edge from parent/.style=
{draw, edge from parent path={(\tikzparentnode.base)
-- +(0,-8pt)
-| (\tikzchildnode)}}}
\hspace{-1.5in}
\begin{tikzpicture}[remember picture]
\matrix
{
\node{\Tree
[.{Family}
[.{Father}
[.{Children}
[{AAA} {BBB} {CCC} ]]
[.{Children}
[{AAAA} {BBBB} {CCCC} ]]]
[.{Mother}
[.{Children}
[{AAAAA} {BBBBB} {CCCCC} ]]
[.{Children}
[{AAAAAAA} {BBBBBB} {CCCCCC} ]]]]};\\
};
\end{tikzpicture}
\end{document}
还有一件事,是否可以将 CCCC 和 AAAAA 连接到 DDDDD,如下图所示
答案1
当我尝试时,您的 MWE 居中,问题可能出在其他地方?尝试将其最小化,看看问题是否仍然存在。关于连接的节点:您可以在 qtree 中指定 tikz 节点名称,然后在这些节点之间绘制一条装饰路径,例如在 CCCC 的西南角和 AAAAA 的西南角之间(如果需要,可以使用 tikzlibrary 进行一些微调,calc
如下所示)。在下面的 MWE 中,我删除了矩阵,因为它干扰了新节点。
\documentclass{article}
\usepackage{tikz-qtree}
\usetikzlibrary{decorations.pathreplacing}
\begin{document}
\tikzset{edge from parent/.style=
{draw, edge from parent path={(\tikzparentnode.base)
-- +(0,-8pt)
-| (\tikzchildnode)}}}
\hspace{-1.5in}
\begin{tikzpicture}[remember picture]
\Tree
[.{Family}
[.{Father}
[.{Children}
[{AAA} {BBB} {CCC} ]]
[.{Children}
[{AAAA} {BBBB} \node(c4){CCCC}; ]]]
[.{Mother}
[.{Children}
[\node(a5){AAAAA}; {BBBBB} {CCCCC} ]]
[.{Children}
[{AAAAAAA} {BBBBBB} {CCCCCC} ]]]]\\
\draw [decorate,decoration={brace,amplitude=10pt,mirror},xshift=-4pt,yshift=0pt](c4.south west) -- (a5.south east) node [black,midway,yshift=-6mm] {DDDDD};
\end{tikzpicture}
\end{document}
结果: