I am new to TikZ and want to draw a simple stack Diagram.
The Diagram should look like:
[a] [b] [c] [d] |-|
|j|
[f ] | |
| |
[g ] | |
| |
[h ] |_|
I hope my ASCII-Art can be seen.
Right now i try to use something like:
\begin{tikzpicture}[x=20pt, y=20pt, node distance=1pt,outer sep = 0pt]
\tikzstyle{box}=[rectangle,draw,anchor=north west,text centered]
\tikzstyle{smallbox}=[box,minimum height=20pt,minimum width=40pt,text width=4em]
\tikzstyle{normalbox}=[box,minimum height=20pt,minimum width=80pt,text width=16em]
\tikzstyle{bigbox}=[box,minimum height=40pt,minimum width=80pt,text width=16em]
\node[smallbox,fill=green!20] (a) at (1,1) {a};
\node[smallbox,fill=green!20] (b) [right = of a] {b};
\node[smallbox,fill=green!20] (c) [right = of b] {c};
\node[smallbox,fill=green!20] (d) [right = of c] {d};
\node[normalbox,fill=green!20] (f) [below = of a] {f};
\node[bigbox,fill=green!20] (g) [below = of f] {g};
\node[normalbox,fill=green!20] (h) [below = of g] {h};
\end{tikzpicture}
But the stacks are not aligned correctly and I am also
having problems with the vertical stack (j
) to the right.
Thank you for your help.
Best Answer
below
always sets the anchor tonorth
, so you have to specify thebelow of = a
for node f before specifying the anchor. Otherwise your anchor specification will be overwritten.north west
anchor of f should be belowa.south west
, not belowa.south
(which is the default).text width
does not include theinner sep
, which is 0.3333em by default (so there is an additional 0.6666em per box plus 3 times the distance between nodes and we have to subtract the inner sep of the large box).minimum width
andtext width
is redundant, especially if the text width is larger.The complete code is: