# How to draw stack diagram with TiKz?

I want to draw a stack diagram looks like this with TiKZ.

I wonder is there way to draw this diagram with automatic positioning like drawing Automaton? Any idea? Thanks in advance.

-
Does this question help? Creating stack with variable width –  Alan Munn Aug 23 '11 at 21:50
@Alan Munn: Thanks for the link. However, that thread is not exactly what I'm looking for because it draws box on top of another. My situation is slightly different though because it divides a tall rectangle box into smaller ones, by drawing a horizontal line. Any other suggestion? –  Chan Aug 23 '11 at 21:55

You could use the shapes.multipart library and use nodes with parts:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{shapes.multipart}
\begin{document}
\begin{tikzpicture}[stack/.style={rectangle split, rectangle split parts=#1,draw, anchor=center}]
\node[stack=5]  {
\nodepart{two}a
\nodepart{three}b
\nodepart{four}c
\nodepart{five}d
};
\end{tikzpicture}

\end{document}


-
Nice one ;) Thanks a lot. It looks very neat indeed. –  Chan Aug 23 '11 at 22:51