Graphics, Figures & Tables ⇒ Drawing blocks of memory
Drawing blocks of memory
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.
- memoryblock.png (10.11 KiB) Viewed 4020 times
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
- localghost
- Site Moderator
- Posts: 9202
- Joined: Fri Feb 02, 2007 12:06 pm
Drawing blocks of memory
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}
Best regards and welcome to the board
Thorsten
Board Rules
Avoidable Mistakes
¹ System: TeX Live 2025 (vanilla), TeXworks 0.6.10
Re: Drawing blocks of memory
- localghost
- Site Moderator
- Posts: 9202
- Joined: Fri Feb 02, 2007 12:06 pm
Drawing blocks of memory
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).bigh29 wrote:[…] This is exactly what I was looking for.
Board Rules
Avoidable Mistakes
¹ System: TeX Live 2025 (vanilla), TeXworks 0.6.10