I am trying to construct an entity relationship diagram using TikZ. I have used this excellent answer given by Mark Wibrow. However, I would prefer that the entity name is given within the matrix, with a line dividing it from its properties, rather than as a label above the matrix.
I had the idea that I ought to be trying to programmatically insert a header row at the beginning of the matrix instead of setting the label text, but I have no idea how to do this. I've spent a while reading various parts of the PGF/TikZ manual and experimenting with the code, but I can't find anything helpful, and at the moment I find PGF/TikZ quite bewildering.
I worked out that I can use row 1/.style in the entity/.code \tikzset command to address the first row. I tried to use row 1/.style={node contents={#1}} to set the text in it, but I guess this gets overwritten later on when the \properties command is used.
So here is the code from the other answer:
\documentclass[a4paper]{article}
\usepackage{tikz}
\usetikzlibrary{shapes.multipart}
\usetikzlibrary{matrix}
\usetikzlibrary{positioning}
\usetikzlibrary{shadows}
\usetikzlibrary{calc}
\makeatletter
\pgfarrowsdeclare{crow's foot}{crow's foot}
{
\pgfarrowsleftextend{+-.5\pgflinewidth}%
\pgfarrowsrightextend{+.5\pgflinewidth}%
}
{
\pgfutil@tempdima=0.5pt%
\advance\pgfutil@tempdima by.25\pgflinewidth%
\pgfsetdash{}{+0pt}%
\pgfsetmiterjoin%
\pgfpathmoveto{\pgfqpoint{0pt}{-6\pgfutil@tempdima}}%
\pgfpathlineto{\pgfqpoint{-6\pgfutil@tempdima}{0pt}}%
\pgfpathlineto{\pgfqpoint{0pt}{6\pgfutil@tempdima}}%
\pgfusepathqstroke%
}
\tikzset{
entity/.code={
\tikzset{
label={#1},
name=#1,
inner sep=0pt,
every entity/.try,
fill=white
}%
\def\entityname{#1}%
},
entity anchor/.style={matrix anchor=#1.center},
every entity/.style={
draw,
},
every property/.style={
inner xsep=0.25cm, inner ysep=0.125cm, anchor=west, text width=1in
},
zig zag to/.style={
to path={(\tikztostart) -| ($(\tikztostart)!#1!(\tikztotarget)$) |- (\tikztotarget)}
},
zig zag to/.default=0.5,
one to many/.style={
-crow's foot, zig zag to
},
many to one/.style={
crow's foot-, zig zag to
},
many to many/.style={
crow's foot-crow's foot, zig zag to
}
}
\def\property#1{\node[name=\entityname-#1, every property/.try]{#1};}
\def\properties{\begingroup\catcode`\_=11\relax\processproperties}
\def\processproperties#1{\endgroup%
\def\propertycode{}%
\foreach \p in {#1}{%
\expandafter\expandafter\expandafter\gdef\expandafter\expandafter\expandafter\propertycode%
\expandafter\expandafter\expandafter{\expandafter\propertycode\expandafter\property\expandafter{\p}\\}%
}%
\propertycode%
}
\begin{document}
\begin{tikzpicture}
\matrix [entity=articles] {
\properties{
classkey,
class_type,
class_desc
}
};
\end{tikzpicture}
\end{document}
Which produces:
Instead I'd like to have something like this:



