I'm trying to draw an ERD diagram. I recycled code from a couple of posts around here and added my own spice, finally ending up with:
\documentclass[border=0.5in]{article} \usepackage{tikz} \usetikzlibrary{shapes.multipart} \usetikzlibrary{matrix} \usetikzlibrary{positioning} \usetikzlibrary{calc} \usepackage{scalefnt} \usepackage{geometry} \usepackage{pdflscape} \makeatletter \pgfarrowsdeclare{oone}{oone} { \pgfarrowsleftextend{+0pt}% \pgfarrowsrightextend{+0pt}% } { \pgfutil@tempdima=0.25pt% \advance\pgfutil@tempdima by0.25\pgflinewidth% \pgfsetdash{}{+0pt}% \pgfsetmiterjoin% \pgfpathmoveto{\pgfqpoint{0\pgfutil@tempdima}{0\pgfutil@tempdima}}% \pgfpathlineto{\pgfqpoint{-8\pgfutil@tempdima}{-8\pgfutil@tempdima}}% \pgfpathmoveto{\pgfqpoint{0\pgfutil@tempdima}{0\pgfutil@tempdima}}% \pgfpathlineto{\pgfqpoint{-8\pgfutil@tempdima}{+8\pgfutil@tempdima}}% \pgfpathmoveto{\pgfqpoint{-12\pgfutil@tempdima}{-8\pgfutil@tempdima}}% \pgfpathlineto{\pgfqpoint{-12\pgfutil@tempdima}{+8\pgfutil@tempdima}}% \pgfusepathqstroke% } \pgfarrowsdeclare{one}{one} { \pgfarrowsleftextend{+0pt}% \pgfarrowsrightextend{+0pt}% } { \pgfutil@tempdima=0.25pt% \advance\pgfutil@tempdima by0.25\pgflinewidth% \pgfsetdash{}{+0pt}% \pgfsetmiterjoin% \pgfpathmoveto{\pgfqpoint{0\pgfutil@tempdima}{0\pgfutil@tempdima}}% \pgfpathlineto{\pgfqpoint{-8\pgfutil@tempdima}{-8\pgfutil@tempdima}}% \pgfpathmoveto{\pgfqpoint{0\pgfutil@tempdima}{0\pgfutil@tempdima}}% \pgfpathlineto{\pgfqpoint{-8\pgfutil@tempdima}{+8\pgfutil@tempdima}}% \pgfusepathqstroke% } \pgfarrowsdeclare{many}{many} { \pgfarrowsleftextend{+0pt}% \pgfarrowsrightextend{+0pt}% } { \pgfutil@tempdima=0.25pt% \advance\pgfutil@tempdima by0.25\pgflinewidth% \pgfsetdash{}{+0pt}% \pgfsetmiterjoin% \pgfpathmoveto{\pgfqpoint{0\pgfutil@tempdima}{0\pgfutil@tempdima}}% \pgfpathlineto{\pgfqpoint{-8\pgfutil@tempdima}{-8\pgfutil@tempdima}}% \pgfpathmoveto{\pgfqpoint{0\pgfutil@tempdima}{0\pgfutil@tempdima}}% \pgfpathlineto{\pgfqpoint{-8\pgfutil@tempdima}{+8\pgfutil@tempdima}}% \pgfpathmoveto{\pgfqpoint{-6\pgfutil@tempdima}{0\pgfutil@tempdima}}% \pgfpathlineto{\pgfqpoint{-14\pgfutil@tempdima}{-8\pgfutil@tempdima}}% \pgfpathmoveto{\pgfqpoint{-6\pgfutil@tempdima}{0\pgfutil@tempdima}}% \pgfpathlineto{\pgfqpoint{-14\pgfutil@tempdima}{+8\pgfutil@tempdima}}% \pgfusepathqstroke% } \pgfarrowsdeclare{omany}{omany} { \pgfarrowsleftextend{+0pt}% \pgfarrowsrightextend{+0pt}% } { \pgfutil@tempdima=0.25pt% \advance\pgfutil@tempdima by0.25\pgflinewidth% \pgfsetdash{}{+0pt}% \pgfsetmiterjoin% \pgfpathmoveto{\pgfqpoint{0\pgfutil@tempdima}{0\pgfutil@tempdima}}% \pgfpathlineto{\pgfqpoint{-8\pgfutil@tempdima}{-8\pgfutil@tempdima}}% \pgfpathmoveto{\pgfqpoint{0\pgfutil@tempdima}{0\pgfutil@tempdima}}% \pgfpathlineto{\pgfqpoint{-8\pgfutil@tempdima}{+8\pgfutil@tempdima}}% \pgfpathmoveto{\pgfqpoint{-6\pgfutil@tempdima}{0\pgfutil@tempdima}}% \pgfpathlineto{\pgfqpoint{-14\pgfutil@tempdima}{-8\pgfutil@tempdima}}% \pgfpathmoveto{\pgfqpoint{-6\pgfutil@tempdima}{0\pgfutil@tempdima}}% \pgfpathlineto{\pgfqpoint{-14\pgfutil@tempdima}{+8\pgfutil@tempdima}}% \pgfpathmoveto{\pgfqpoint{-18\pgfutil@tempdima}{+8\pgfutil@tempdima}}% \pgfpathlineto{\pgfqpoint{-18\pgfutil@tempdima}{-8\pgfutil@tempdima}}% \pgfusepathqstroke% } \begin{document} \tikzset{ entity/.code={ \tikzset{ rounded corners, name=#1, inner sep=2pt, every entity/.try, label=below:#1 }% \def\entityname{#1}% }, entity anchor/.style={matrix anchor=#1}, every entity/.style={ draw, }, every property/.style={ inner xsep=0.20cm, inner ysep=0.075cm, anchor=west, text width=1in }, zig zag to/.style={ to path={(\tikztostart) -| ($(\tikztostart)!#1!(\tikztotarget)$) |- (\tikztotarget)} }, zig zag to/.default=0.5, many to one/.style={ many-one, zig zag to }, one to omany/.style={ one-omany, 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{landscape} \scalefont{0.5} \begin{tikzpicture}[every node/.style={font=\ttfamily}, node distance=0.5in] \matrix [entity=Rent] { \properties{ ID : int(11), StartDate : datetime, EndDate : datetime, PickupDate : datetime, ReturnDate : datetime, PickupMiles : int(11), ReturnMiles : int(11), Missing : bool, VehicleVIN : varchar(255), EmployeeUsername : varchar(255), CustomerID : int(11), DepartureGarage : int(11), ArrivalGarage : int(11), OfferID : int(11), Kasko : bool, TPI : bool, CDW : bool, TW : bool, DER : bool, RestrictAge : bool, ExtraMileageUnits : int(11) } }; \matrix [entity=Employee, above=of Rent] { \properties{ Username : varchar(255), Password : varchar(255), Name : varchar(255), LastName : varchar(255) } }; \matrix [entity=Vehicle, left= of Rent] { \properties{ VIN : varchar(255), Plate : varchar(255), Seating : int(11), Doors : int(11), 4WD : bool, Year : int(11), Diesel : bool, Displacement : double, Consumption : double, LPG : bool, ManualShift : bit, Autonomy : double, Discriminator : int(11), ModelID : int(11), HousedInGarage : int(11), Retired : bool, FullHybrid : bool, Mileage : int(11) } }; \draw[one to omany] (Vehicle) to (Rent); \draw[one-omany] (Employee) to (Rent); \end{tikzpicture} \end{landscape} \end{document}
Now, I would like to have the label inside the node, maybe with a separator or something. ATM I get:
But I would rather have:
Can anybody suggest a way to do so?
Thank you a whole lot.