I planned to illustrate how a quadtree data structure I'm using is implemented, showing all internal pointers and arrays. The image will look something like this:
(Here, if a pointer points at the symbol ∅ it means that it is a null pointer, i.e. it has the value 0)
I wanted to use something like in this question to illustrate what the linking looks like. What I noticed is that the code featured in this question defines the style box
which is used to draw an array that consists of two elements.
My first question is: When should a style be used? Why doesn't the code in the question I linked to use a macro for drawing the rectangle that represents the array for example?
A second I have question is: How do they work? I haven't been able to find very much about them in the pgf manual (see pages 493–494), so I really don't know at all what is going on when a style is used. Is the code defined in the style kind of like copied and pasted into the place where the style is used, and how exactly does that happen?
A third I have question is: If a style is used to draw a rectangle like in this case, how can I make it draw the rectangle so that it is scaled accordingly with the definitions of x and y? For example, I begin my TikZ picture with the code \begin{tikzpicture}[x={(.035\textwidth,0)},y={(0,.035\textwidth)}]
. The value of x
and y
may vary from picure to picture, and so also the scale of what is drawn. How can I make the rectangle use the values of x
and y
? I have tried to change inner sep=2ex
in the code in the question I linked to, which is an absolute distance, to a distance that depends on x
and y
but I haven't succeeded.
Best Answer
I think it's preferable to use
style
every time and every where. The code is more readable and there if you look atpgfkeys
you can find a lot of possibilities that you can use insidestyles
. below you can find a first version to get something like you want. Perhaps you can find a better answer because there are a lot of possibilities but you need to use styles in each way. If necessary, I can explain the next code.Question 1 : always because it's easy to modify a picture with the styles
It's possible to scale the tree with
[x=.5cm,y=.5cm]
and withscale
inside the styles for the nodes.Update