Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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.

share|improve this question
    
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

3 Answers 3

up vote 12 down vote accepted

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

share|improve this answer
    
Nice one ;) Thanks a lot. It looks very neat indeed. –  Chan Aug 23 '11 at 22:51

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, ...).

share|improve this answer
2  
Welcome to TeX-SX! You may have a look at our starter page for a quick intro if you wish to familiarize yourself with our format. To improve the answer, would you like to add a minimal working example as well as the result it provides? –  Claudio Fiandrino May 6 '13 at 16:24
    
+1 Nice package, very useful! As we like to be answers on this site to be self-contained, it would be nice if you could add a minimal working example that demonstrates your package. Moreover, if we recommend our own work (which is perfectly okay!) we tend to make this somehow explicit in the answer (e.g., add a "written by me" or "my drawstack package"). –  Daniel May 6 '13 at 20:59

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}

Stack Example

The example is taken as is from here where you can find more complex examples such as:

  1. Grouping cells into stack frames
  2. Stack and Base pointers
  3. Highlighting some cell e.t.c.
share|improve this answer
    
Welcome to TeX.SX! –  Adam Liter Dec 9 at 3:58

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.