2

I am using tikz-qtree to draw a hierarchical tree. However, the position of the tree out of the page. Could you help me to adjust the tree to center of page? Thank you

My current code that manually setting as

\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}

enter image description here

One more thing, is it possible to connect CCCC and AAAAA to DDDDD as below figure

enter image description here

Jame
  • 689

1 Answers1

3

Your MWE is centered when I try it, possibly the problem is somewhere else? Try to make it as minimal as possible and see if the problem persists. Regarding the connected nodes: you can specify tikz node names in a qtree and then draw a decorated path between those nodes, for example between the south west corner of CCCC and the south west corner of AAAAA (with some finetuning if necessary using the calc tikzlibrary as shown below). In the MWE below I've removed the matrix because it interfered with the new nodes.

\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}

Result:

enter image description here

Based on: Draw Curly Braces in TikZ

Marijn
  • 37,699