# Tikz: Styling a node to display text on the right of a dot

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}

\tikzstyle{every entity} = [top color=white, bottom color=blue!40,
draw=blue!20!black!70, drop shadow, thin, rounded corners=2pt]
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:

But I am trying to accomplish something like this:

-
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
Welcome to TeX.SX. Does the answer of Drawing relationships between elements of a database helps you? – Claudio Fiandrino Dec 17 '12 at 14:57
@Jake, thank you for your suggestion. I added an example along with images of what I'm trying to achieve. – Riccardo Sabbatini 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. – Riccardo Sabbatini Dec 17 '12 at 17:03
@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 – Riccardo Sabbatini Dec 17 '12 at 21:20

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:

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}

\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}

-
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 5:04
Works perfectly fine, thank you :) – Riccardo Sabbatini Dec 18 '12 at 14:50