How to change tikzset the text is automatically added to the link

\documentclass{minimal}
\usepackage{tikz}
\usetikzlibrary{shapes,positioning,fit}
\begin{document}

\begin{tikzpicture}

\node[circle,draw] (a) at (0,0){a};

\node[circle,draw] (b) at (5,2){b};

\end{tikzpicture}
\end{document}

-
What text are you talking about? If you to add a text node along an arrow you can just add a node after (b) and add the pos=0.5 key. –  Matthew Leingang Mar 28 '13 at 20:44
Do you want to change the link text (the aaa in your example) or the link style (for example, the positioning of the label above or below the line)? –  Jake Mar 28 '13 at 21:16
I want to automatically add the text "aaa" with the style –  rpapa Mar 28 '13 at 21:36
\tikzset{mylink/.style={dashed,->, every to/.append style={to path=-- node {aaa} (\tikztotarget) \tikztonodes}}} and then you can use \draw [myling] (a) to (b); –  Qrrbrbirlbel Mar 28 '13 at 23:18
ok, but can be replaced (a) to (b) by (a) -- (b). –  rpapa Mar 29 '13 at 8:18

You have about three ways to get automatically nodes with styles.

The easiest one is to use a to path operator and simply change the used to path to

-- node {#1} (\tikztotarget) \tikztonodes


(This will of course only work with -- paths.)

If you insist on using -- in your path, you can use the decorations.markings library and automatically mark these paths with a node:

mark=at position .5 with {\node {#1};}


This will also work with non-straight (--/line to) paths.

The third option is only available with the current CVS version of PGF and uses the so-called edge nodes. Similar to solution 1, I change the every edge style to onclude this edge node. (We could also have used every to and to in the path.)
The advantage here is that we still can change the path to for example a curve to.

Code

\documentclass[tikz]{standalone}
\usetikzlibrary{decorations.markings}
\tikzset{
dashed,
->,
},
aaa/.style={
every to/.append style={
to path=-- node {#1} (\tikztotarget) \tikztonodes
}
},
aaa/.default=aaa,
bbb/.style={
decoration={
markings,
mark=at position .5 with {\node {#1};}
},
postaction=decorate
},
bbb/.default=bbb,
ccc/.style={
every edge/.append style={edge node=node {#1}}
},
ccc/.default=ccc
}
\begin{document}
\begin{tikzpicture}
\node[circle,draw] (a) at (0,0) {a};
\node[circle,draw] (b) at (5,2) {b};
\end{tikzpicture}

\begin{tikzpicture}
\node[circle,draw] (a) at (0,0) {a};
\node[circle,draw] (b) at (5,2) {b};