# setting a tikzset which has draw inside as style of a \node

I need to get different color edges for my rectangular nodes.

I found this question How do I set only one side of a tikz node's border color?

The \tikzset mentioned in the answer has input arguments and I don't know how to set them when used with \node.

I have tried to remove the arguments and set the styles but the all I get is a xetex in infinite loop.

\documentclass{article}
\usepackage{tikz}
\usepackage{pgfplots}
\tikzset{%
mynode/.style ={
\draw[thick,red,line cap=butt,shorten <= -0.5\pgflinewidth,shorten >= 0.5\pgflinewidth] (a.south west) |- (a.north east);
\draw[thick,blue,line cap=butt,shorten <= 0.5\pgflinewidth,shorten >= -0.5\pgflinewidth] (a.south west) -| (a.north east);

}
}
\begin{document}
\begin{figure}[ht]
\begin{center}
\begin{tikzpicture}
\tikzstyle{main}=[rectangle, minimum width = 30mm,minimum height = 50mm, thick, draw =black!80, node distance = 6mm]

\node[main] (m)  {$A$ };
\node[mynode] [right=of m] (x2) { $R$}; %commenting this line out with eliminate the infinite loop
\end{tikzpicture}
\end{center}
\end{figure}
\end{document}


• It would be very helpful if you provide (non) working minimal example (MWE) which we can copy in own computers and compile it. – Zarko Jun 2 '16 at 18:17

if you looking for something like this

than the following MWE can be of help:

\documentclass[tikz,border=3mm]{standalone}
\newcommand\ppbb{path picture bounding box}
\tikzset{%
mynode/.style = {rectangle,
path picture={%
\draw[thick,red]    (\ppbb.south west) |- (\ppbb.north east);
\draw[thick,blue]   (\ppbb.south west) -| (\ppbb.north east);
},% end of path picture
},
}% end of tikzset
\begin{document}
\begin{tikzpicture}
\node (x2) [mynode] {$R$};
\end{tikzpicture}
\end{document}


edit: or slightly different appearance

obtained with the following (slightly modified) code:

\documentclass[tikz,border=3mm]{standalone}
\newcommand\ppbb{path picture bounding box}
\tikzset{%
myline/.style={draw=#1, thick, shorten <=0.5\pgflinewidth},
mynode/.style = {rectangle,
path picture={%
\draw[myline=red]    (\ppbb.south west) |- (\ppbb.north east);
\draw[myline=blue]   (\ppbb.north east) |- (\ppbb.south west);
},% end of path picture
},
}% end of tikzset
\begin{document}
\begin{tikzpicture}
\node (x2) [mynode] {$R$};
\end{tikzpicture}
\end{document}

• would it be at all possible to pass arguments in \node? – saied Vanguard Jun 2 '16 at 18:46
• @saiedVanguard, sorry, I do not understand you. In the first solution all arguments are in definition of it style (except definition os \ppbb), in second is style for border lines defined separately because with this is code for node style definition concise and clear. If you like to have all this in definition of mynode style, you can replace \ppbb with path picture bounding box and myline=<color> with <color>,thick, shorten <=0.5\pgflinewidth. – Zarko Jun 2 '16 at 18:57
• @saiedVanguard You can use #1 to represent the argument in the definition of mynode and then say \node [mynode={<list of options>};. Is that what you mean? You are already giving \node arguments! (Or as close as it comes to doing that, anyway, in TikZ.) – cfr Jun 3 '16 at 3:35
• @cfr I meant an actual line of code that would pass some arguments. the <> and list is a bit vague. – saied Vanguard Jun 7 '16 at 0:43
• @saiedVanguard ?? – cfr Jun 7 '16 at 0:45