I want to build an E/R diagram in LaTeX such that there should be rhombus for representing the relations and squares for representing the entity sets. I dont want to import graphics in LaTeX i.e. import the graphics after drawing it in some other image drawing software but want to do it in LaTeX itself.Could someone suggest me some good links to read from??
2 Answers
You can do this easily with TikZ.
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{shapes}
\colorlet{relation@colour}[rgb]{blue}
\colorlet{entity@colour}[rgb]{red}
\tikzset{relation/.style={%
shape=diamond,draw=relation@colour!50!gray,
ultra thick,fill=relation@colour!25!white,
minimum height=2em},
entity/.style={%
shape=rectangle,draw=entity@colour!50!gray,
ultra thick,fill=entity@colour!25!white,
minimum height=2em}}
\begin{document}
\begin{tikzpicture}
\draw (0,0) node(tikz) [entity] {TikZ}
(tikz.east) + (1,0)
node(draws)[relation,anchor=west] {draws}
(draws.east) + (1,0)
node(er diagrams)[entity,anchor=west] {\textsc{er} diagrams}
(tikz) -- (draws)
(draws) -- (er diagrams);
\end{tikzpicture}
\end{document}
user defined ER diagram http://csweb.ucc.ie/~dongen/TeX-SX/er.png.
As a matter of fact, TikZ also provides an er
library. The following shows how to use it.
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{er}
\begin{document}
\begin{tikzpicture}
\draw (0,0) node(tikz) [entity] {TikZ}
(tikz.east) + (1,0)
node(draws)[relationship,anchor=west] {draws}
(draws.east) + (1,0)
node(er diagrams)[entity,anchor=west] {\textsc{er} diagrams}
(tikz) -- (draws)
(draws) -- (er diagrams);
\end{tikzpicture}
\end{document}
A simple example, run it with xelatex
or latex->dvips->ps2pdf
\documentclass{article}
\usepackage{pst-node,pst-dbicons}
\begin{document}
\seticonparams{entity}{shadow,fillcolor=red!30,fillstyle=solid}
\seticonparams{relationship}{shadow,fillcolor=blue!20,fillstyle=solid}
\entity{Country} \hspace*{6cm} \entity{City}
\relationshipbetween{Country}[0:n]{City}[1:1]{in}/\ncarc[arcangle=20]/(0.4)
\relationshipbetween{Country}[1:1]/\ncarc[arcangle=-18]/%
{City}[0:1]/\ncarc[arcangle=-12]/{Capital}/\ncarc[arcangle=-30]/(0.6)
\end{document}
tikz
. Here are a few questions on this site that might be useful: neural-network-representation, produce-the-following-exact-hexagon, connect-tikz-nodes-running-around-nodes