
Supongamos que tengo 2 qtrees que quiero colocar uno debajo del otro:
\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}
Ahora los árboles se superponen. El primero tiene un comentario 'la la la', que reside en un nodo separado. Si no lo tuviera, podría poner ambos árboles en nodos y posicionar nodos. ¿Pero cómo posicionar qtrees desnudos? Entonces sus raíces coincidirían horizontalmente y el segundo árbol estaría debajo de 'la la la'.
Respuesta1
Además de usar dos imágenes TikZ diferentes separadas por \\
, puedes usar el nodo agregado manualmente note-1
para desplazar todo el segundo árbol hacia abajo.
También puedes utilizar un nodo del Árbol ya definido pero necesitas restablecer sus coordenadas con la ayuda de una coordenada auxiliar (Código 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
El |-
se asegura de que 2
esté colocado debajo del 1
.
Código 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}
Código 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}
Producción
Respuesta2
Puedes usar a scope
con un desplazamiento apropiado para el segundo árbol:
\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}