qtreeの配置方法

qtreeの配置方法

2 つの qtree があり、それらを互いの下に配置したいとします。

\documentclass{article}
\usepackage{tikz}
\usepackage{tikz-qtree,tikz-qtree-compat}
\usetikzlibrary{positioning}
\begin{document}
\begin{tikzpicture}
\Tree
[.{1}
    [.1-1 ]
    [.\node (1) {1-2}; ]
]
\node [below = 0.5cm of 1.south] (note-1) {la la la};
\draw[-]
      (note-1.north) -- (1.south);
\Tree
[.{2}
    [.2-1 ]
    [.2-2 ]
]
\end{tikzpicture}
\end{document}

ここに画像の説明を入力してください

これでツリーが重なり合います。1 つ目のツリーには「la la la」というコメントがあり、別のノードに存在します。これがなければ、両方のツリーをノードに配置してノードを配置できます。しかし、ベア qtree をどのように配置すればよいのでしょうか。ルートが水平に一致し、2 番目のツリーが「la la la」の下になるようにします。

答え1

で区切られた 2 つの異なる TikZ 画像を使用するだけでなく\\、手動で追加したノードを使用してnote-12 番目のツリー全体を下に移動することもできます。

ツリーの既に定義されているノードを使用することもできますが、補助座標を使用してその座標を再確立する必要があります (コード 2)。

% somewhere in the tree:
          [. \node (lowest node) {1-2-2-1-1};  ]

% outside of tree:
\coordinate (aux1) at (lowest node);

% The coordinate aux1 can now be used for placement, e.g.
% below=of toptree |- aux1

は、 がの下に配置されている|-ことを確認します。21

コード 1

\documentclass[tikz]{standalone}
\usepackage{tikz,tikz-qtree,tikz-qtree-compat}
\usetikzlibrary{positioning}
\begin{document}
\begin{tikzpicture}
\Tree
[.\node (toptree) {1};
    [.1-1 ]
    [.\node (1) {1-2}; ]
]
\node [below = 0.5cm of 1.south] (note-1) {la la la};
\draw[-] (note-1.north) -- (1.south);

\begin{scope}[every tree node/.append style={below=of toptree |- note-1.south}]
\Tree
[.2
    [.2-1 ]
    [.2-2 ]
]
\end{scope}
\end{tikzpicture}
\end{document}

コード2

\documentclass[tikz]{standalone}
\usepackage{tikz,tikz-qtree,tikz-qtree-compat}
\usetikzlibrary{positioning}
\begin{document}
\begin{tikzpicture}
\Tree
[.\node (toptree) {1};
    [.1-1 ]
    [.1-2 
      [.1-2-1 
        [.1-2-2-1 
          [. \node (lowest node) {1-2-2-1-1};  ]
        ]
      ]
    ]
]
\coordinate (aux1) at (lowest node);

\begin{scope}[opacity=.5,every tree node/.append style={below=of toptree |- lowest node}]
\Tree
[.2
    [.2-1 ]
    [.2-2 ]
]
\end{scope}
\begin{scope}[every tree node/.append style={below=of toptree |- aux1}]
\Tree
[.2
    [.2-1 ]
    [.2-2 ]
]
\end{scope}
\end{tikzpicture}
\end{document}

出力

ここに画像の説明を入力してください ここに画像の説明を入力してください

答え2

scope2 番目のツリーには、適切なシフトを使用して を使用できます。

\documentclass{article}
\usepackage{tikz}
\usepackage{tikz-qtree,tikz-qtree-compat}
\usetikzlibrary{positioning}

\begin{document}
\begin{tikzpicture}
\Tree
[.1
    [.1-1 ]
    [.\node (1) {1-2}; ]
]
\node [below = 0.5cm of 1.south] (note-1) {la la la};
\draw[-]
      (note-1.north) -- (1.south);
\begin{scope}[yshift=-3cm]
\Tree
[.2
    [.2-1 ]
    [.2-2 ]
]
\end{scope}
\end{tikzpicture}
\end{document}

ここに画像の説明を入力してください

関連情報