答案1
用箭头可以相当简单地制作鱼尾纹。剩下的就是使用styles
宏进行简化,这可以通过多种方式完成。以下是其中一种:
\documentclass[border=0.25in]{standalone}
\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=above:#1,
name=#1,
inner sep=0pt,
every entity/.try,
fill=white,
general shadow={
shadow xshift=0.0625in,
shadow yshift=-0.0625in,
opacity=0.5,
fill=black!50
}
}%
\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}[every node/.style={font=\ttfamily}, node distance=1.25in]
\matrix [entity=Class] {
\properties{
classkey,
class_type,
class_desc
}
};
\matrix [entity=Product, right=of Class-classkey, entity anchor=Product-classkey] {
\properties{
classkey,
prodkey,
prod_name,
pkg_type
}
};
\matrix [entity=Sales, right=of Product-classkey, entity anchor=Sales-classkey] {
\properties{
perkey,
classkey,
prodkey,
prod_name,
storekey,
promokey,
quantity,
dollars
}
};
\matrix [entity=Period, right=of Sales-perkey, entity anchor=Period-perkey] {
\properties{
perkey,
date,
day,
week,
month,
qtr,
year
}
};
\matrix [entity=Promotion, below=of Period, entity anchor=Promotion-promokey] {
\properties{
promokey,
promo_type,
promo_desc,
value,
start_date,
end_date
}
};
\matrix [entity=Store, below=of Product, entity anchor=Store-storekey] {
\properties{
storekey,
mktkey,
store_type,
store_name,
street,
city,
state,
zip
}
};
\matrix [entity=Market, left=of Store-mktkey, entity anchor=Market-mktkey] {
\properties{
mktkey,
hq_city,
hq_state,
district,
region
}
};
\draw [one to many] (Class-classkey) to (Product-classkey);
\draw [one to many] (Product-classkey) to (Sales-classkey);
\draw [one to many] (Product-prodkey) to (Sales-prodkey);
\draw [many to one] (Sales-perkey) to (Period-perkey);
\draw [one to many] (Market-mktkey) to (Store-mktkey);
\draw [many to one] (Sales-storekey) to (Store-storekey);
\draw [many to one] (Sales-promokey) to (Promotion-promokey);
\end{tikzpicture}
\end{document}
答案2
以下是使用 PGF 3.x 语法并遵循 PGF 手册第 100.4 节中的示例的“鱼尾纹”箭头声明。
\pgfdeclarearrow{
name = ErdMany,
parameters = {
\the\pgfarrowlength
},
setup code = {
% End values
\pgfarrowssettipend{\pgfarrowlength}
\pgfarrowssetbackend{0pt}
\pgfarrowssetlineend{\pgfarrowlength}
\pgfarrowssetvisualbackend{\pgfarrowlength}
% Convex hull
\pgfarrowshullpoint{0pt}{0pt}
\pgfarrowshullpoint{\pgfarrowlength}{\pgfarrowlength}
\pgfarrowshullpoint{\pgfarrowlength}{-\pgfarrowlength}
% Save
\pgfarrowssavethe\pgfarrowlength
},
drawing code = {
\pgfpathmoveto{\pgfqpoint{\pgfarrowlength}{0.5\pgfarrowlength}}
\pgfpathlineto{\pgfqpoint{0pt}{0pt}}
\pgfpathlineto{\pgfqpoint{\pgfarrowlength}{-0.5\pgfarrowlength}}
\pgfusepathqstroke
},
defaults = { length = 10pt }
}
crow's feet
对于我来说,它是最新 PGF的直接替代品。