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.
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.
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}
Here is an example of using drawstack.sty:
\documentclass{article}
\usepackage{drawstack}
% Use this instead if you don't want colors.
% \usepackage[nocolor]{drawstack}
\begin{document}
% The main feature of the package is to define an environment
% drawstack.
\begin{drawstack}
% Within the environment, draw stack elements with \cell{...}
\cell{First cell}
\cell{Second cell}
\end{drawstack}
\end{document}
The example is taken as is from here where you can find more complex examples such as:
You may have a look at drawstack.sty, which provides a few simples macros to draw stacks (tailored for execution stack, with addresses, stack pointer, ...).