在鱼尾纹处绘制 ERD

在鱼尾纹处绘制 ERD

我正在用 UML 工具绘制我的实体关系图,我是 TeX 编写的新手,现在想用 latex 绘制它。我的 ERD 图像如下所示;
请帮我编写代码并告诉我我使用了哪些包。谢谢

答案1

这是一个可行的解决方案,其中box样式由两部分定义rectangle split。框之间的线条使用与下面相同的模式。FROM起点TO终点位于上方(下方)0.5 厘米处 特殊点调用label,3 条线散开。

\draw[red,thick] (FROM) node[right]{\color{black}1} --  node[right]{\color{black}suppliess} ($(To)+(-1,0.5)$) coordinate(label){} --([xshift=-1cm]TO) 
(label) -- ([xshift=-1.5cm]TO) 
(label) --node[right]{\color{black}$\star$}([xshift=-0.5cm]TO);  

在此处输入图片描述

代码

\documentclass[border=10pt]{standalone}
%\usepackage[margin=1cm]{geometry}
\usepackage{tikz}
\usetikzlibrary{shapes.multipart,calc,positioning}
\tikzset{
box/.style={draw=red, fill=yellow, minimum width=3cm, rectangle split, rectangle split parts=2}
}

\begin{document}
\begin{tikzpicture}

% draw all nodes
\node[box](A) {\textbf{vender}
\nodepart{two}vender\textunderscore id (PK) };
\node[box, below =2cm of A] (B) {\textbf{repair}
\nodepart{two}\parbox[t]{3cm}{\texttt{item\_id} (FK)\\
\texttt{repair\_id} (PK)\\
\texttt{vender\_id} (FK)
 }};

\node[box,right=2cm of A](C) {\textbf{Inventory type}
\nodepart{two}grp\textunderscore type (PK) };
\node[box, right =2cm of C] (D) {\textbf{Order item}
\nodepart{two}\parbox[t]{3cm}{\texttt{Ol\_line\_num} (PK) \\
\texttt{o\_id} (FK)\\
\texttt{grp\_type} (FK)
 }};

\node[box,below=5cm of C](E) {\textbf{Item}
\nodepart{two}\parbox[t]{3cm}{\texttt{item\_id} (PK)\\
\texttt{vendor\_id} (FK)}};
\node[box, below right=2cm and 3cm of E] (F) {\textbf{Storage}
\nodepart{two}\parbox[t]{3cm}{\texttt{stirage\_id} (PK)\\
\texttt{location\_id} (FK)
 }};

\node[box, below left=5cm and 1cm of E] (L) {\textbf{Location}
\nodepart{two}\parbox[t]{3cm}{\texttt{location\_id} (PK)
 }};

\node[box, right=12cm of A] (R) {\textbf{order}
\nodepart{two}\parbox[t]{3cm}{\texttt{o\_id} (FK)\\
\texttt{user\_id} (FK)\\
\texttt{vender\_id} (FK) }};
\node[box, below =2cm of R] (S) {\textbf{user}
\nodepart{two}\texttt{repair\_id} (PK) };

% draw lines
\draw[red,thick] (A.east)node[right]{\color{black}1} --  node[right]{\color{black}suppliess} ($(E.north)+(-1,0.5)$) coordinate(e2){} --([xshift=-1cm]E.north) 
(e2) -- ([xshift=-1.5cm]E.north) 
(e2) --node[right]{\color{black}$\star$}  ([xshift=-0.5cm]E.north);  

\draw[red,thick] (C.south) -- node[right]{\color{black}includess} ($(E.north)+(0,0.5)$) coordinate(e){} --(E.north) 
(e) -- ([xshift=-5mm]E.north) 
(e) -- ([xshift=5mm]E.north);  

\draw[red,thick] (E.east)node[below right]{\color{black}1} -| ($(F.north)+(0,0.5)$) coordinate(f2){}  node[midway,above]{\color{black}is found in} -- (F.north) 
(f2) -- ([xshift=-5mm]F.north) 
(f2) --node[right]{\color{black}$\star$}  ([xshift=5mm]F.north);  

\draw[red,thick] (E.west) -| node[below]{\color{black}needs} ($(B.east)+(0.5,0)$) coordinate(e2){} --(B.east) 
(e2) -- ([yshift=-5mm]B.east) 
(e2) -- ([yshift=5mm]B.east);  

\draw[red,thick] (L.east)node[above right]{\color{black}1}  -| ($(F.south)+(0,-0.5)$) coordinate(f){}  node[below]{\color{black}is found in} -- (F.south) 
(f) -- ([xshift=-5mm]F.south) 
(f) -- node[right]{\color{black}$\star$} ([xshift=5mm]F.south);  

\draw[red,thick] (C.east) node[above right]{\color{black}1} --($(D.west)-(0.5,0)$) coordinate(d){} --(D.west) 
(d) -- ([yshift=-5mm]D.west) 
(d) -- ([yshift=5mm]D.west);  

\draw[red,thick] (A.south)node[below right]{\color{black}1} --node[right]{\color{black}perform} ($(B.north)-(0,-0.5)$) coordinate(b){} --(B.north) 
(b) -- ([xshift=-5mm]B.north) 
(b) --node[right]{\color{black}$\star$}  ([xshift=5mm]B.north);  

\draw[red,thick] (A.north)node[above right]{\color{black}1} --++(0,2cm) node[pos=0.5,right]{\color{black}recieves} -| ($(R.north)-(0,-0.5)$) coordinate(s){} -- (R.north) 
(s) -- ([xshift=-5mm]R.north) 
(s) -- node[right]{\color{black}$\star$} ([xshift=5mm]R.north); 

\draw[red,thick] (S.north) -- node[right]{\color{black}givess}($(S.north)+(0,1.5)$) coordinate(r){} --(R.south) 
(r) -- ([xshift=-5mm]R.south) 
(r) -- node[right]{\color{black}$\star$} ([xshift=5mm]R.south);  

\draw[red,thick] (R.west) node[above left]{\color{black}1}--  node[below]{\color{black}contains}($(D.east)+(0.5,0)$) coordinate(d2){} --(D.east) 
(d2) -- ([yshift=-5mm]D.east) 
(d2) -- node[right]{\color{black}$\star$} ([yshift=5mm]D.east);  

\end{tikzpicture}
\end{document}

相关内容