I am aware that TikZ tries to create shapes based on minimum size and the text content, but I wish to create some rectangles of arbitrary size as the ones in the following figure:
As you can see, the width of the "Requested size" rectangle should be equal to the total width of the "Free block" rectangles, yet each "Free block" and each "Used block" rectangle has a different width, even if they have the same text.
I have tried to tackled it with a matrix like this example, but I could really not set the rectangle's width, as I am not messing around with "text width" inside the nodes. This is what I have written so far for the last line of the figure:
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{shapes,matrix,positioning}
\begin{document}
\begin{tikzpicture}[field/.style={outer sep=0pt, draw, minimum
height=12mm, minimum width=#1\linewidth,font=\small,anchor=center,
text width=18mm,align=center}]
\matrix (A) [matrix of nodes, column sep=-\pgflinewidth,
row 1/.style={nodes={field=.1}}] {
|[field=.2,draw=none]| Memory layout &
|[field=.3,fill=red]| Used block &
|[fill=green]| Free block &
|[fill=green]| Free block &
|[field=.2, fill=green]| Free block &
|[fill=red]| Used block \\
};
\end{tikzpicture}
\end{document}
And this is the output:
Thanks in advance!
Edit: As @OlgaK commented, my code was using different names for the shape, so I have fixed the code and the output image.






text widthwould certainly be the quickest solution here. I don't it would interfere with your nodes as long as your text is around the same length. – Alenanno Apr 21 '16 at 17:40