[Tex/LaTex] Set style on all nodes on top of edges in tikz

edgenodestikz-pgftikz-styles

I have some edges with a node 'on top of it' defined as

\path (source) edge node {some text} (target);

But now it just prints some text directly on top of the node, which makes it difficult to read.

What I want is a white background. I know that I can obtain this with

\path (source) edge node [fill=white] {some text} (target);

but I want this to happen to ALL my nodes, which are on top of an edge.

One way to do it, is to use

\tikzset{every node/.style={fill=white}}

but then it will happen to all my nodes and not just those node which are on top of edges.

Another way to do it is to set a class manually on all those nodes with

\tikzset{white bg/.style={fill=white}}
\path (source) edge node [white bg] {some text} (target);

but it would be better if it could be done for all nodes automatically.

Are there any tikz key which does something like

\tikzset{every node on edge/.style={fill=white}}

Best Answer

There's an every edge style, and you can put an every node style definition inside that, so borrowing some code from gernot's answer:

enter image description here

\documentclass[border=1mm]{standalone}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}[every edge/.append style={every node/.style={fill=blue}}]
\node (source) {S};
\draw (4,0) node (target) {T}; % just to show that this isn't blue either
\path (source) edge node {some text} (target);
\end{tikzpicture}
\end{document}