6

I am trying to create a LaTeX document using the Tikz library, more particularly an E/R Diagram. I have downloaded the tikz-er2 additional library, but I am having an issue with the display of attributes.

In my class we've always used a different notation, putting the name of the attribute on the right of a dot, and linking the entity to this dot.

How would I accomplish this using tikz styling?

EDIT: This is a (very) simplyfied version of my code, which compiles just fine:

\documentclass[a4paper,12pt,landscape]{article}

\usepackage[landscape]{geometry}
\usepackage{graphicx}

\usepackage{tikz-er2}
\usepackage{verbatim}
\usepackage[active,tightpage]{preview}
\PreviewEnvironment{tikzpicture}
\setlength\PreviewBorder{5pt}

\begin{document}

\thispagestyle{empty}

\usetikzlibrary{positioning}
\usetikzlibrary{shadows}

\tikzstyle{every entity} = [top color=white, bottom color=blue!40, 
                            draw=blue!20!black!70, drop shadow, thin, rounded corners=2pt]
\tikzstyle{every attribute} = [shading=radial, inner color=white, outer color=yellow!50!gray!20!white, 
                               draw=yellow, node distance=1cm, drop shadow, thin,align=center]

\centering
\begin{tikzpicture}[node distance=1.5cm]

  \node[entity] (ent1) {Entity1};
  \node[attribute] (attr1) [right=of ent1] {\key{Attr1}} edge (ent1);

\end{tikzpicture}

\end{document}

The above code produces this diagram:

enter image description here

But I am trying to accomplish something like this:

enter image description here

ricky92
  • 63
  • 4
    Hi Riccardo, welcome to the site! Could you maybe post a mockup of what you're trying to achieve, together with a minimal example document (starting from \documentclass) showing how you generate your diagrams? That will make it much easier for others to come up with a solution. – Jake Dec 17 '12 at 14:14
  • 1
  • @Jake, thank you for your suggestion. I added an example along with images of what I'm trying to achieve. – ricky92 Dec 17 '12 at 17:02
  • @ClaudioFiandrino, thank you as well, but I am already using the tikz-er2 package (as I have said in the question). The only problem is I want to get a different style for attributes, the second image might help you get the idea better. – ricky92 Dec 17 '12 at 17:03
  • I don't think that the tikz-er2 is a standard pacakge, at least I don't seem to have it. The MWE needs to be compilable by others. – Peter Grill Dec 17 '12 at 19:20
  • 1
    @PeterGrill It is not, but I have no idea how I'm supposed to provide a compilable MWE with such kind of package. Other than providing a link to download it, I see no other way for other people to compile it. The package can be downloaded from here: link – ricky92 Dec 17 '12 at 21:20

1 Answers1

4

The easiest way is to remove all drawing styles from the attribute node, and using instead a new style for the edge from the attribute to the entity, which draws a small circle at the beginning. One way is to simply use the "circled arrow" edge[O-]. Another more customizable way is the following.

I define a decoration named draw circle which draws a circle at the beginning of the line. You can style the circle as you want, and choose its size too:

\tikzset{
 draw circle/.style = {
   decoration = {show path construction,
     lineto code = {
       \filldraw[black,fill=white] (\tikzinputsegmentfirst) circle(4pt);
       }
    }, decorate,
 }
}

Then you use the above style as a postaction for the edge. In order to simplify the syntax, I define a new style to do so:

\tikzset{
   attr/.style = { postaction = {draw circle} }
}

You need also to remove all the drawing styles of the attribute node:

\tikzset{
   every attribute/.style = {draw=none,node distance=1cm }
}

And then, in the diagram you simple use:

  \node[attribute] (attr1) [right=of ent1] {\key{Attr1}} edge[attr] (ent1);

to get:

Result

Putting all together:

\documentclass[a4paper,12pt,landscape]{article}
\usepackage[landscape]{geometry}
\usepackage{graphicx}
\usepackage{tikz-er2}
\usepackage{verbatim}
\usepackage[active,tightpage]{preview}
\PreviewEnvironment{tikzpicture}
\setlength\PreviewBorder{5pt}
\usetikzlibrary{positioning}
\usetikzlibrary{shadows,decorations.pathreplacing}

\begin{document}
\tikzset{
 draw circle/.style = {
   decoration = {show path construction,
     lineto code = {
       \filldraw[black,fill=white] (\tikzinputsegmentfirst) circle(4pt);
       }
    }, decorate,
 },
 attr/.style = { postaction = {draw circle} },
 every entity/.style = { top color=white, bottom color=blue!40,
                         draw=blue!20!black!70, drop shadow, thin, rounded corners=2pt },
 every attribute/.style =  { draw=none,node distance=1cm }
}
\begin{tikzpicture}

  \node[entity] (ent1) {Entity1};
  \node[attribute] (attr1) [right=of ent1] {\key{Attr1}} edge[attr] (ent1);

\end{tikzpicture}

\end{document}
JLDiaz
  • 55,732
  • 1
    You can use \draw (\tikzinputsegmentfirst) circle(<radius>); with adding shorten < = <radius> to the attr or the draw circle style. Advantage: Color assigned to the edge gets used for the circle, too, and no filling is needed. Also, did you maybe mean a lowercase o- arrow? – Qrrbrbirlbel Dec 18 '12 at 05:04