Is there some way to draw a B+ tree in latex? It would look something like the picture below (ignoring the animations)
Animation linked here: http://i.stack.imgur.com/JRcmY.gif
Screenshot of the start of the animation:
trees
Is there some way to draw a B+ tree in latex? It would look something like the picture below (ignoring the animations)
Animation linked here: http://i.stack.imgur.com/JRcmY.gif
Screenshot of the start of the animation:
While I'd normally second Will Robertson's comment, since TikZ is fantastic and worth learning, I think TikZ's overkill for this situation. I personally find its tree specification syntax bulkier than necessary. My preferred tool for the job is the qtree package (which is on CTAN, too, and is apparently included in both TeX Live and MikTeX). The package is really simple to use. Consider the following TeX:
\Tree[.IP [.NP [.Det \textit{the} ]
[.N\1 [.N \textit{package} ]]]
[.I\1 [.I \textsc{3sg.Pres} ]
[.VP [.V\1 [.V \textit{is} ]
[.AP [.Deg \textit{really} ]
[.A\1 [.A \textit{simple} ]
\qroof{\textit{to use}}.CP ]]]]]]
This produces the following tree:
That's all it takes! And what's great about it is that the TeX description reads like the tree. I can glance at the TeX, and I instantly know what the created tree is going to look like. The basic syntax is simply [.node-name subtrees... ]
; \qroof
, which draws the triangle, requires its node name at the end, instead. The \1
is just a shortcut for a math-mode prime. In addition, qtree will always render _
and ^
as sub- and super-scripts, too. (Unless you turn this off.)
In general, you can provide node names at the beginning ([.+ 1 [.* 2 3 ]]
) or the end ([ 1 [ 2 3 ].* ].+
); you can even provide node names in both places, but then they must match (unsurprisingly). This, incidentally, is why \qroof
takes its node name the way it does. You can even leave the node name off entirely to get a node with a smooth join. If any of this is unclear, check out the manual.
Now, qtree as-is has one downside, which is that it is designed for simple trees. It does offer limited support for changing inter-node spacing, framing parts of trees, and things like that, but it's not capable of doing anything incredibly fancy. But luckily, if you want that, you can still get it: enter tikz-qtree. This package allows you to leverage the full power of TikZ to draw your trees. The two obvious features are: (a) instead of text, the labels in a tree can be arbitrary \node
s; and (b) you can redefine how it draws the edges to get arrows, dashed lines, curving edges, and so on. But it's more powerful than just this: if you embed a \Tree
into a TikZ picture, you can do whatever you want with the nodes, such as circle them, draw arrows between them for a transformation, etc.
Maybe you don't need this power now, but the take-home message is that using qtree won't lock you in to the simple trees. If you decide that you want the more powerful trees, all you need to do is change one import; everything will keep working the way it did, but you get more power, too. I'm not sure if tikz-qtree this actually uses qtree under the hood or not, but either way, all the syntax for qtree still works, and the output is identical, at least as far as I can tell.
(PS: Linguists, please excuse/correct any errors in the above tree; it's been a year or two since my syntax course.)
Merry Christmas everyone!
Christmas tree with balls, candles and snowflakes
Now pic
is very useful. An update was necessary
Instead of
\newsavebox{\mycandle}
\savebox{\mycandle}{
\begin{tikzpicture}[scale=.1]
\shade[top color=yellow,bottom color=red] (0,0) .. controls (1,.2) and (1,.5) .. (0,2) .. controls (-1,.5) and (-1,.2) .. (0,0);
\fill[yellow!90!black] (.8,0) rectangle (-.8,-5);
\end{tikzpicture} }
\tikzset{ mycandle/.pic ...
The code
% !TEX TS-program = pdflatex
\documentclass[border=2mm]{standalone}
\usepackage[usenames,dvipsnames]{xcolor}
\usepackage{tikz}
\usetikzlibrary{ shapes,decorations.shapes,decorations.fractals,decorations.markings,shadows}
\tikzset{ mycandle/.pic={
\shade[top color=yellow,bottom color=red] (0,0) .. controls (1,.2) and (1,.5) .. (0,2) .. controls (-1,.5) and (-1,.2) .. (0,0);
\fill[yellow!90!black] (.8,0) rectangle (-.8,-5); }}
\tikzset{
paint/.style={draw=#1!50!black, fill=#1!50},
my star/.style={decorate,decoration={shape backgrounds,shape=star},star points=#1}}
\begin{document}
\begin{tikzpicture}[every pic/.style={scale=.1,transform shape} ,
ball red/.style={
decorate, decoration={ markings,mark=between positions .2 and 1 step 3cm
with
{ \pgfmathsetmacro{\sz}{2 + .5 * rand}
\path[shading=ball,ball color=red] (0,0) circle[radius=\sz mm]; }}},
ball blue/.style={decorate, decoration={ markings, mark=between positions 0.1 and .9 step 3cm
with {\pgfmathsetmacro{\sz}{2 + .5 * rand}
\path[shading=ball,ball color=blue] (0,0) circle[radius=\sz mm]; }}}]
\draw[fill=Maroon,ultra thick]
(.75,-1) .. controls (.5,.5) and (.5,3) .. (0.5,4)
-- (-0.5,4) .. controls (-.5,3) and (-.5,.5) .. (-.75,-1) ;
\draw[ultra thick,fill=green!50!black]
(0,10) .. controls (0,8) and (1,7) .. (1.5,7)
.. controls (1,7) and (1,7) .. (0.5,7.25)
.. controls (1.5,5) and (2.5,4) .. (3,4)
.. controls (2,4) and (1.25,4) .. (1,4.5)
.. controls (2,2) and (3.5,2) .. (4,2)
.. controls (1,1) and (-1,1) .. (-4,2)
.. controls (-3.5,2) and (-2,2) .. (-1,4.5)
.. controls (-1.25,4) and (-2,4) .. (-3,4)
.. controls (-2.5,4) and (-1.5,5) .. (-0.5,7.25)
.. controls (-1,7) and (-1,7) .. (-1.5,7)
.. controls (-1,7) and (0,8) .. (0,10)
;
\pic foreach \candle in {(2,5),(-2,5),(0.5,7.5),(-0.5,7.5),(-3,2.5), (3,2.5),
(1.5,1.75),(-1.5,1.75)} at \candle {mycandle} ;
\node [star, star point height=.5cm, minimum size=.5cm,draw,fill=yellow,thick]
at (0,10) {};
\begin{scope}[decoration={shape sep=.2cm, shape size=.25cm}]
\draw [my star=6, paint=red] (-4,2)
.. controls (0,2) and (1,3.5) .. (1,4.40);
\draw [my star=6, paint=red] (-1.5,5.40)
.. controls (0,5.40) and (0.5,6.5) .. (0.5,7);
\draw [my star=6, paint=blue] (4,2)
.. controls (0,2) and (-1,3.5) .. (-1,4.40);
\draw [my star=6, paint=blue] (1.5,5.40)
.. controls (0,5.40) and (-0.5,6.5) .. (-0.5,7);
\end{scope}
% the balls
\path[ball red]
(0,10) .. controls (0,8) and (1,7) .. (1.5,7)
.. controls (1,7) and (1,7) .. (0.5,7.25)
.. controls (1.5,5) and (2.5,4) .. (3,4)
.. controls (2,4) and (1.25,4) .. (1,4.5)
.. controls (2,2) and (3.5,2) .. (4,2)
.. controls (1,1) and (-1,1) .. (-4,2)
.. controls (-3.5,2) and (-2,2) .. (-1,4.5)
.. controls (-1.25,4) and (-2,4) .. (-3,4)
.. controls (-2.5,4) and (-1.5,5) .. (-0.5,7.25)
.. controls (-1,7) and (-1,7) .. (-1.5,7)
.. controls (-1,7) and (0,8) .. (0,10)
;
\path[ball blue]
(0,10) .. controls (0,8) and (1,7) .. (1.5,7)
.. controls (1,7) and (1,7) .. (0.5,7.25)
.. controls (1.5,5) and (2.5,4) .. (3,4)
.. controls (2,4) and (1.25,4) .. (1,4.5)
.. controls (2,2) and (3.5,2) .. (4,2)
.. controls (1,1) and (-1,1) .. (-4,2)
.. controls (-3.5,2) and (-2,2) .. (-1,4.5)
.. controls (-1.25,4) and (-2,4) .. (-3,4)
.. controls (-2.5,4) and (-1.5,5) .. (-0.5,7.25)
.. controls (-1,7) and (-1,7) .. (-1.5,7)
.. controls (-1,7) and (0,8) .. (0,10)
;
% the snow
\foreach \i in {0.5,0.6,...,1.6}
\fill [white!80!blue,decoration=Koch snowflake,opacity=.9]
[shift={(rand*5,rnd*8)},scale=\i]
[double copy shadow={opacity=0.2,shadow xshift=0pt,
shadow yshift=3*\i pt,fill=white,draw=none}]
decorate {
decorate {
decorate {
(0,0) -- ++(60:1) -- ++(-60:1) -- cycle
}
}
};
\end{tikzpicture}
\end{document}
Best Answer
I would do this in TikZ. Section 18.1 of the version 2.10 manual shows how to make trees. The nodes on the trees are a little nonstandard, but perhaps section 16.3 on multi-part nodes would be helpful.
Here's a quick mockup:
It's going to be more work to get the vertical lines doubled like in your example. The code for the
rectangle split
shape may need to be altered.