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.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am trying to find a way to use TikZ to create as much as possible a collection of lecture notes (1), (2) for an introductory level course in data structures for a public free uni of my country.

I have been successful so far in finding trees, arrays and so on, but I was not able to find an starter point for representing memory and elements inside of them (wanted) with some arrows to point out concepts (optional) with diagonal arrows and code alignment (wanted).

I found that in other questions TeX community was receptive for such requests, I hope this one wouldn't be a problem.

The image below is from a book named Structures Gently Through C who has the visualization I am trying to achieve with TikZ.

enter image description here

enter image description here

share|improve this question
up vote 4 down vote accepted

Here's a sample which combines most of the features that you desire:

%% Packages and libraries needed for this MWE
%% Two commands for representing content.
    char `a' in memory\par       
    (65 = ascii code)


  %% Building the boxes representing memory locations
  \foreach \x in {0,1,...,20}
    \node[inner sep=1pt] (BL\x) at (0,-\x)   {};
    \node[inner sep=1pt] (UR\x) at (1,-\x+1) {};
    \node (MM\x) at ($(BL\x)!0.5!(UR\x)$) {};
    \draw (BL\x) rectangle (UR\x);
    \node[anchor=south east] at (BL\x.north west) {\memoryNumber};

  %% Label columns:
  \node (MEMLOC) at ($(MM0)+(0,2cm)$) { \parbox{2cm}{\centering Memory Location} };
  \node (ADDRESS) at ($(MEMLOC)-(0.75,0)$) {\parbox{2cm}{\centering Address} };
  \draw [-{Stealth[scale=1.5]}] (MEMLOC) -- (MM0|-UR0);
  \draw [-{Stealth[scale=1.5]}] (ADDRESS) -- ($(MM0|-UR0)-(0.75,0)$);

  %% Drawing arrows spanning memory locations
  \foreach \x/\y in {3/0,
    \node (M\x-\y) at ($(BL\x)!0.5!(UR\y)$) {\aeDiagonalNumber};
    \draw[-{Stealth[scale=1.5]}]  (M\x-\y) -- (BL\x) ; 
    \draw[-{Stealth[scale=1.5]}]  (M\x-\y) -- (UR\y) ;

  %% Adding content to memory location "18"
  \node at (MM18) {65};
  \node (RHS18) at (MM18-|UR18) {};
  %% Adding a side note to memory location "18"
  \node[draw,anchor=west] (BOX18) at ($(RHS18)+(1cm,0)$) {\memorySixtyFive};
  \draw [-{Stealth[scale=1.5]}] (RHS18.center) -- (BOX18);

  \node (1byte) at ($(UR10)+(0.5,0)$) { \parbox{1.5cm}{\centering One location = 1 byte}};
  \draw [-{Stealth[scale=1.5]}] (1byte) -- ($(1byte|-UR5)-(0,0.5)$) -- ($(UR5)-(0,0.5)$);



enter image description here

Hopefully this illustrates enough of the techniques you can use to design the presentation in the manner you want.

share|improve this answer
Thank you so much A. Ellett. Now I can finish the class in time for tomorrow! :-) – Oeufcoque Penteano Dec 7 '13 at 2:46
A.Ellett would you happen to know why arrows.meta can't be located? Is that a new package or something like this? I actually used it without the arrow symbols. No matter how much I google, all I could find was that it was supposed to change the arrow head size. But apparently no one else seems to know about it :( " I can't find file `tikzlibraryarrows.meta.code.tex'." – Oeufcoque Penteano Dec 12 '13 at 6:23
You'll need the latest CVS version of TikZ to get the arrow libraries. Sorry I forgot to mention that. – A.Ellett Dec 12 '13 at 18:13
Thank you! :) I managed to get it to work around with triangles and the sorts. I will look into this later! – Oeufcoque Penteano Dec 13 '13 at 1:38

Your Answer


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.