Oct 24, 2022

Position a Graph, Scope, etc. in TikZ

I found that the best way is to wrap a \mbox or \fbox in a node.

Code:

\documentclass[margin=0pt, 12pt]{standalone} \usepackage{tikz} \usetikzlibrary{positioning,calc,graphs,graphdrawing,arrows.meta} \usegdlibrary{trees} \begin{document} \begin{tikzpicture} \matrix[column sep=10em] { \node (a) { \mbox{ \begin{tikzpicture}[>=Latex] \graph[binary tree layout, nodes={draw=black, circle, inner sep=.5em, outer sep=0pt}]{ p[as=$p$] -> { n[as=$n$] -> { A[as=$A$], B[as=$B$] }, C[as=$C$] } }; \end{tikzpicture} } }; & \node (b) { \mbox{ \begin{tikzpicture}[>=Latex] \graph[binary tree layout, nodes={draw=black, circle, inner sep=.5em, outer sep=0pt}]{ n[as=$n$] -> { A[as=$A$], p[as=$p$] -> { B[as=$B$], C[as=$C$] } } }; \end{tikzpicture} } }; \\ }; \draw [-Latex] ($(a.east)+(0, .2em)$) -- ($(b.west)+(0, .2em)$) node [midway, above, sloped] {Right Rotation}; \draw [Latex-] ($(a.east)-(0, .2em)$) -- ($(b.west)-(0, .2em)$) node [midway, below, sloped] {Left Rotation}; \end{tikzpicture} \end{document}