Summary
- Fixed the node names. For easier reference, I named the node from top to bottom, left to right with
a,b,...
.
- As suggested by Qrrbrbirlbel, I used the
rectangle split
node shape available in the library shapes.multipart
instead of the tabular
environment.
- Instead of defining a new
to path
I used the brace
decoration from the decorations.pathreplacing
library instead and set amplitude=0pt
. Hacky, but it works.
- I removed
\scalebox
and replaced this with scale=0.8
.
- Update
I encolsed each |
with $...$
. As mentioned by Qrrbrbirbel in comment, to draw the pipes: |
, use \usepackage[T1]{fontenc}
in your preamble: How to insert pipe symbol in (La)TeX?. For good measure, write also \usepackage[utf8]{inputenc}
.
- Instead of defining the coordinates in terms of the default ones in the
rectangle split
node shape, I defined them relative to only two coordinates of the node.
- I replaced
\tikzstyle
, which is deprecated, with \tikzset
.
- There is no need to define
red
as color since this is already predefined. Also, there is no need to load the color
package since tikz
uses xcolor
internally.
Updated Code
\documentclass[tikz,border=5]{standalone}
%\documentclass[10pt]{article}
%\usepackage[margin=1in]{geometry}
%\usepackage{tikz}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usetikzlibrary{shapes.multipart,calc,decorations.pathreplacing}
\tikzset{
my shape 1/.style={circle, draw},
my shape 2/.style={
rectangle split,
rectangle split parts=#1,
draw,
anchor = center,
rectangle split horizontal},
}
\begin{document}
\begin{tikzpicture}
\tikzset{level 1/.style={sibling distance=50mm},
level 2/.style={sibling distance=30mm}}
\node (a) [my shape 1] {\textcolor{red}{2}|2}
child {node(b) [my shape 1] {\textcolor{red}{2}|4}
child {node(e) [my shape 1] {\textcolor{red}{2}|4}}
child {node(f)[my shape 2=6,scale=0.8] {
\textcolor{red}{2}|4 \nodepart{two} \textcolor{red}{2}|4 \nodepart{three} \textcolor{red}{2}|4 \nodepart{four} \textcolor{red}{2}|4 \nodepart{five} \textcolor{red}{2}|4 \nodepart{six} \textcolor{red}{2}|4
}}
child {node(g) [my shape 1] {\textcolor{red}{5}|2}}
}
child {node(c)[my shape 2=6,scale=0.8] {
\textcolor{red}{2}|4 \nodepart{two} \textcolor{red}{2}|4 \nodepart{three} \textcolor{red}{2}|4 \nodepart{four} \textcolor{red}{2}|4 \nodepart{five} \textcolor{red}{2}|4 \nodepart{six} \textcolor{red}{2}|4
}}
child {node(d) [my shape 1] {\textcolor{red}{7}|2}
child {node(h) [my shape 1] {\textcolor{red}{2}|4}}
child {node(i)[my shape 2=6,scale=0.8] {
\textcolor{red}{2}|4 \nodepart{two} \textcolor{red}{2}|4 \nodepart{three} \textcolor{red}{2}|4 \nodepart{four} \textcolor{red}{2}|4 \nodepart{five} \textcolor{red}{2}|4 \nodepart{six} \textcolor{red}{2}|4
}}
child {node(j) [my shape 1] {\textcolor{red}{5}$|$3}}
};
\foreach \xleft/\leftpos in {1/0.416,3/0.2083,5/.375,7/.542,9/.7083,11/.875} {
\coordinate (c\xleft) at ($(c.south west)!\leftpos!(c.south east)$);
\coordinate (f\xleft) at ($(f.north west)!\leftpos!(f.north east)$);}
\foreach \x/\arrowcol in {1/blue,3/green,5/red,7/yellow,9/orange,11/purple}
\draw [->,\arrowcol] (c\x) .. controls ++(-90:0.5) and ++(0:0.5) .. ($(c\x)!.5!(f\x)$)
($(c\x)!.5!(f\x)$) .. controls ++(180:0.5) and ++(90:0.5) .. (f\x);
\foreach \xright/\rightpos in {2/.125,4/.2917,6/.4583,8/.625,10/.7917,12/.9583} {
\coordinate (c\xright) at ($(c.south west)!\rightpos!(c.south east)$);
\coordinate (i\xright) at ($(i.north west)!\rightpos!(i.north east)$);}
\foreach \x/\arrowcol in {2/blue,4/green,6/red,8/yellow,10/orange,12/purple}
\draw [->,\arrowcol,dashed] (c\x) .. controls ++(-90:0.5) and ++(0:0.5) .. ($(c\x)!.5!(i\x)$)
($(c\x)!.5!(i\x)$) .. controls ++(180:0.5) and ++(90:0.5) .. (i\x);
\draw [postaction={draw,decorate,decoration={brace,raise=-3pt,amplitude=0pt},dashed,red}] (a) -- (b);
\end{tikzpicture}
\coordinate (a*) at (c9);
\coordinate (b*) at ([yshift=-0.2cm]a*);
\draw (a*) -- (b*);
\draw ([xshift=-0.3cm]b*) -- ([xshift=0.3cm]b*);
\foreach \x in {-0.8,-0.4,0,.4,0.8}
\draw ([xshift=\x em]b*) -- +(-0.1,-0.2);
\end{document}
Updated Output
rectangle split
node shape? Although the PGF manual only shows the anchors of a vertically split node, there are probably also proper anchors for a horizontally split node (.text south
,.two south
,.three south
, …?).d
,f
,g
/pgf/decoration/raise
option may come in handy.crosses
). On the other sidedecoration={lineto,raise=6pt}
does not work either, so more effort will be needed to make that work. The next best thing would be a customto path
, I guess.