I'm using rectangle split to draw link nodes:
How to ensure every rectangle split with the same size, especially with the same width! no matter it is empty or with one digit or with two digits (maximum two digits, or like "-1")
MWE(my code):
\documentclass[border=10pt]{standalone}
\usepackage{tikz, tkz-graph}
\usetikzlibrary{arrows,positioning}
\thispagestyle{empty}
\usepackage{memorygraphs}
\tikzset{
phead/.style={
rectangle, draw, text height=3mm, text width=3mm,
text centered, node distance=3cm, inner sep=0pt
},
block/.style={
draw,
%text height=height("I"),
%text depth=depth("I"),
anchor=mid,
%inner sep=0pt,
%minimum width=0.6cm,
every block,
},
arity/.style={
block,
rectangle split,
rectangle split parts=#1+1,
rectangle split horizontal,
rectangle split every empty part={},
rectangle split empty part width=0.6cm,
minimum size=0.6cm,
}
}
\begin{document}
\begin{tikzpicture}[memory graph]
\node[phead, label=above:head] (head) {};
\def\prevname{head}
\foreach \name/\labela/\val in {1/7/,2/7/,3//,4/12/,5/13/,6/0/-1}{
\ifnum \name=1
\node[block,arity=1,right=of \prevname] (a\name) {\labela};
\draw[ref] (\prevname.center) -- (a\name);
\else
\node[block,arity=1,right=of \prevname.arg 1 east] (a\name) {\labela};
\draw[ref] (\prevname.arg 1 center) -- (a\name);
\fi
\xdef\prevname{a\name}
}
\end{tikzpicture}
\end{document}
You can see I've override some tikz style of the memorygraphics in the code above, like block
and arity
Some code(style) of package memeorygraphics
: https://ctan.org/pkg/memorygraphs
\tikzset{
memory graph/.style={
node distance=1.5em,
},
every block/.style={},
block/.style={
draw,
text height=height("I"),
text depth=depth("I"),
anchor=mid,
every block,
},
block/.append code={%
\let\arg\memorygraphs@arg%
\gdef\memorygraphs@arity{0}%
},
block mark north east/.style={
append after command={
\pgfextra
\pgfinterruptpath
\draw[#1]
($(\tikzlastnode.head north east)-(\ifnum\memorygraphs@arity=0 .5\pgflinewidth\else0\fi,.5\pgflinewidth)$)
-- +(0,-\memorygraphs@marklength)
-- ($(\tikzlastnode.head north east)-(\ifnum\memorygraphs@arity=0 .5\pgflinewidth\else0\fi+\memorygraphs@marklength,.5\pgflinewidth)$)
-- cycle;
\endpgfinterruptpath
\endpgfextra
},
},
block mark south east/.style={
append after command={
\pgfextra
\pgfinterruptpath
\draw[#1]
($(\tikzlastnode.head south east)+(\ifnum\memorygraphs@arity=0 -.5\pgflinewidth\else0\fi,.5\pgflinewidth)$)
-- +(0,\memorygraphs@marklength)
-- ($(\tikzlastnode.head south east)+(\ifnum\memorygraphs@arity=0 -.5\pgflinewidth\else0\fi-\memorygraphs@marklength,.5\pgflinewidth)$)
-- cycle;
\endpgfinterruptpath
\endpgfextra
},
},
block mark north west/.style={
append after command={
\pgfextra
\pgfinterruptpath
\draw[#1]
($(\tikzlastnode.head north west)+(.5\pgflinewidth,-.5\pgflinewidth)$)
-- +(0,-\memorygraphs@marklength)
-- ($(\tikzlastnode.head north west)-(-.5\pgflinewidth-\memorygraphs@marklength,.5\pgflinewidth)$)
-- cycle;
\endpgfinterruptpath
\endpgfextra
},
},
block mark south west/.style={
append after command={
\pgfextra
\pgfinterruptpath
\draw[#1]
($(\tikzlastnode.head south west)+(.5\pgflinewidth,.5\pgflinewidth)$)
-- +(0,\memorygraphs@marklength)
-- ($(\tikzlastnode.head south west)+(.5\pgflinewidth+\memorygraphs@marklength,.5\pgflinewidth)$)
-- cycle;
\endpgfinterruptpath
\endpgfextra
},
},
arity/.style={
block,
rectangle split,
rectangle split parts=#1+1,
rectangle split horizontal,
rectangle split every empty part={},
rectangle split empty part width=.2em,
},
arity/.append code={%
\pgfmathsetcount\c@pgf@counta{\pgfkeysvalueof{/pgf/rectangle split parts}}%
\ifnum\c@pgf@counta=0\else\advance\c@pgf@counta by-1 \fi
\xdef\memorygraphs@arity{\the\c@pgf@counta}%
},
ref/.style={
{Circle[length=3pt]}-Latex,
shorten <=-1.5pt,
rounded corners=.2em,
},
}