I don't think that you should make a style with arguments for that, mainly because the styles you'll create won't reduce the number of arguments you'll still need to give. I'll just propose a setup more TikZ like and try to bring some light into the matter.
First of all, \tikzstyle
is deprecated, one should now set a style with the Key Handler /.style={keys}
which naturally accepts one argument. So first we create the set of styles that don't take any arguments, our foundation:
block/.style={rectangle, fill=gray, text centered, minimum height=8mm,node distance=10em, rounded corners=1mm},
my line style/.style={ultra thick, -{Latex}, draw=CornflowerBlue},
my label style/.style={text=Tomato, font=\itshape, fill=white},
Now we can build up to variants which use our foundation styles but take some arguments, for example:
mylabel/.style={edge node={node[my label style]{#1}}}
my edge/.style={my line style, mylabel=#1},
my curved edge/.style n args={4}{my line style, out=#1, in=#2, looseness=#3, mylabel=#4},
normal edge/.style={my line style, out=-90, in=90, mylabel=#1},
The first one makes the label (there are several solutions for labeling an edge, I used the first one that poped into my head), it applies the label style we created beforehand and sets the text. The second applies the line style to the edge and also receives an argument which is passed to the label party. There are variants to the curved edges, one that takes four arguments for a complete flexibility and one that that has in
and out
preset so only the label needs to be passed, the looseness can be adjusted as normally is.
Another thing to be taken into account is the every anything
styles, like every node
, every edge
, every path
and so on. They're particulary useful when you want to set every thing to the same style and avoid repetion.
I've also taken the liberty to suggest a few other ways that the drawing can be made, using the positioning library (it could be made as a tree too, probably wiser) and the arrows.meta
library which replaces the deprecated arrows
library.
MWE
\documentclass{article}
\usepackage[svgnames]{xcolor}
\usepackage{tikz}
\usetikzlibrary{arrows.meta,positioning}
\begin{document}
\begin{tikzpicture}[%
block/.style={rectangle, fill=gray, text centered, minimum height=8mm, rounded corners=1mm}
,my line style/.style={ultra thick, -{Latex}, draw=CornflowerBlue}
,my label style/.style={text=Tomato, font=\itshape, fill=white}
,every edge/.style={my line style}
,my edge/.style={my line style, mylabel=#1}
,my curved edge/.style n args={4}{my line style, out=#1, in=#2, looseness=#3, mylabel=#4}
,normal edge/.style={my line style, out=-90, in=90, mylabel=#1}
,mylabel/.style={edge node={node[my label style]{#1}}}]
\scoped[every node/.style=block, node distance=6em and 3em]{
\path (0,0) node (n01) {Node 01}
node[below right= of n01] (n02) {Node 02}
node[below left= of n01] (n03) {Node 03};
};
\path (n01) edge[mylabel=Label 1] (n02)
edge[normal edge=Label 2] (n03);
\end{tikzpicture}
\end{document}
Part VII Utilities
->82 Key Management
->82.4 Key Handlers
->.code args
or.style args
.