Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I am draw my entity relationship diagram in a UML tool, I am new to TeX writing and now want to draw it in latex. The image of my ERD is given below;
Please help me with code and tell me which packages I use. Thanks

share|improve this question
2  
Have you seen this: ctan.org/pkg/pgf-umlcd ? (I never tried it, only found the link.) –  mbork Apr 19 at 6:47
1  
The word “receives” is misspelt in your diagram. –  alexwlchan Apr 19 at 8:00

1 Answer 1

up vote 5 down vote accepted

This is a possible solution where box style is defined rectangle split with two parts. Lines between boxes use mostly the same pattern as below. FROM a starting point TO an end point located either 0.5cm above (below) a special point call label where 3 lines spread out.

\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);  

enter image description here

Code

\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}
share|improve this answer
    
Thank you for your kind response :) –  Muhammad Toseef Apr 20 at 17:54

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.