Graphics, Figures & TablesDrawing blocks of memory

Information and discussion about graphics, figures & tables in LaTeX documents.
Post Reply
bigh29
Posts: 2
Joined: Thu Feb 10, 2011 3:19 am

Drawing blocks of memory

Post by bigh29 »

<me>TeX newbie</me>

I would like to know how to illustrate a block of computer memory in TeX. Is this done with tables? Or is there a package geared for this sort of thing?

The image in the attachment shows what I am trying to do. Another good example is the depiction of the Quick sort algorithm in the Cormen et al Algorithms book. (page 172 in the third edition of CLRS).

Sorry if this is an FAQ. I tried searching for the answer, but could not find the right mix of keywords.

H


Edit by localghost: Preferably no external links (see Board Rules). Attachments go onto the forum server where possible.
Attachments
A block of computer memory.
A block of computer memory.
memoryblock.png (10.11 KiB) Viewed 4021 times

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

Learn LaTeX easily with newest books:

The LaTeX Beginner's Guide: 2nd edition and perfect for students writing a thesis

The LaTeX Cookbook: 2nd edition full of practical examples for mathematics, physics, chemistry, and more

LaTeX Graphics with TikZ: the first book about TikZ for perfect drawings in your LaTeX thesis

User avatar
localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

Drawing blocks of memory

Post by localghost »

A table would be inappropriate. It requires a graphical solution since you have to connect some cells with arrows. Such a solution could be based on pgf/tikZ. The code below shows a basic structure.

Code: Select all

\documentclass{minimal}
\usepackage{tikz}
\usetikzlibrary{matrix}

\begin{document}
  \begin{tikzpicture}[%
    >=stealth,
    shorten >=2pt,
    thick
  ]
    \matrix (block) [%
      matrix of nodes,
      nodes={%
        draw,
        anchor=center,
        minimum width=4em,
        minimum height=2em
      }
    ] {%
      1 & \node[fill=gray!25]{2}; & \node[fill=gray!25]{3}; & \node[fill=gray!25]{4}; & \node[fill=gray!25]{\ldots}; & \node[fill=gray!25]{D-1}; & \node[fill=gray!25]{D}; & D+1  & \ldots & 2D+1\\
    };

    \path[->] (block-1-1.north) edge [bend left=30] (block-1-2.north)
              (block-1-1.north) edge [bend left=30] (block-1-7.north)
              (block-1-2.south) edge [bend right=30] (block-1-8.south);
    \draw[thin] (block-1-1.south east) +(0,-0.2) -- +(0,-2) (block-1-7.south east) +(0,-0.2) -- +(0,-2);
    \draw (block-1-1.south) node[below=1.5cm] {Root}
          (block-1-4.south east) node[below=1.5cm] {Children of root node}
          (block-1-9.south) node[below=1.5cm] {Children of node 2};
  \end{tikzpicture}
\end{document}
For own enhancements it is necessary that you read the package manual. You don't need to go through the whole document but only browse the passages relevant. But this still will be am major part of the manual.


Best regards and welcome to the board
Thorsten
bigh29
Posts: 2
Joined: Thu Feb 10, 2011 3:19 am

Re: Drawing blocks of memory

Post by bigh29 »

Thanks for the suggestion. This is exactly what I was looking for.
User avatar
localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

Drawing blocks of memory

Post by localghost »

bigh29 wrote:[…] This is exactly what I was looking for.
Then please mark the topic (not the last post) accordingly as you have already been directed and written in Section 3 of the Board Rules (to be read before posting).
Post Reply