[Tex/LaTex] How to draw stack diagram with TiKz

tikz-pgf

I want to draw a stack diagram looks like this with TiKZ.
enter image description here

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

Best Answer

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}

output of code

Related Question