创建鱼尾纹风格的 ER 图,而不是陈式 ER 图

创建鱼尾纹风格的 ER 图,而不是陈式 ER 图

我需要画一些实体关系图我的计算机课程作业到目前为止都是用 LaTeX 写的。可以使用手动绘制它们tikz,但这听起来有点不愉快,所以我找到了具有的ertikz

这个方法确实很好用,我也想用,但是它会产生陈式默认图表。

在此处输入图片描述

有人知道我是否可以/如何制作吗鱼尾纹有图表吗?

在此处输入图片描述

答案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的直接替代品。

相关内容