\documentclass{article}


\usepackage{erdiagram}
\usepackage{ukdate}

\title{Examples of using erdiagram.sty}
\author{Peter McBrien}

\begin{document}

\maketitle

\begin{center}
\begin{scriptsize}
\begin{tikzpicture}[er diagram]

  \erentity[]{person};

  \erkeyattribute[above=of person]{person}{name}{above};
  \erattribute[above=of person,xshift=\erattributespace]{person}{salary}{right};
  \erattribute[above=of person,xshift=-\erattributespace]{person}{age}{left};

  \erentity[below=of person,xshift=-\subclassxshift]{engineer};

  \ermultiattribute[below=of engineer]{engineer}{skill}{below};
  
  \erisa{engineer}{person};

  \erentity[right=of engineer]{manager};

  \erattribute[below=of manager,
    xshift=\erhalfattributespace]{manager}{mobile}{right};
  \eroptionalmultiattribute[below=of manager,
    xshift=-\erhalfattributespace]{manager}{car}{left};

  \erisa{manager}{person};
  
  \errelationship[right=of person]{works in};

  \erattribute[above right=of works in]{works in}{start\_date}{right};
  \eroptionalattribute[below right=of works in]{works in}{end\_date}{right};

  \erentity[right=of works in]{department};
  \erkeyattribute[right=of department]{department}{dname}{right};

  \erinvolvement{works in}{person}{0:N}{below};
  \erinvolvement{works in}{department}{0:N}{above};

  \errelationship[above=of works in]{member};

  \erattribute[right=of member]{member}{role}{right};
  
  \erentity[above=of member]{project};

  \erkeyattribute[right=of project]{project}{pcode}{right};
  \erattribute[right=of project,yshift=\erattributespace]{project}{name}{right};
  \erattribute[right=of project,yshift=-\erattributespace]{project}{budget}{right};


  \erinvolvement{member}{works in}{0:1}{left};
  \erinvolvement{member}{project}{0:N}{right};

  \ergeneralisation[left=of person]{person}{comms};
  
  \erentity[left=of person comms,yshift=\subclassyshift]{email\\user};
  \erattribute[above=of email user]{email user}{email}{above};
  \draw (email user) to[dogleg,arm=4.5em] (person comms);

  \erentity[below=of email user]{non-email\\user};
  \erattribute[below=of non-email user]{non-email user}{pigeon\_hole}{below};
  \draw (non-email user) to[dogleg,arm=4.5em] (person comms);

  \erweakentity[below=of department,xshift=8em]{swipe\\card};

  \erkeyattribute[below=of swipe card]{swipe card}{issue}{below};

  \errelationship[left=of swipe card]{for};

  \erinvolvement{for}{swipe card}{\keyname{1:1}}{above};
  \erinvolvement{for}{person.south east}{0:N}{above};
  
\end{tikzpicture}
\end{scriptsize}
\end{center}

\end{document}
