# Decorate node with rectangle

I want to distinguish vertices in a network by decorating them with additional paths. The solution from here works perfectly for single lines, but I need more shapes so I also want to draw a small rectangle inside the node in the same manner. An attempt which in my eyes should work is shown below in pat2 (pat1 is just for comparison). The problem is that it doesn't, and I don't see why.

\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{calc}
\tikzstyle{cvertex}=[solid, circle,draw=black,line width=1 pt, inner sep=2pt]
\tikzset{
local edge style/.style = {line width=1pt, line cap=round, shorten <=2pt, shorten >=2pt},
pat1/.style = {append after command={
(\tikzlastnode.west)
edge[local edge style]
(\tikzlastnode.east)
}},
pat2/.style = {append after command={
[draw, line width=1pt]
($(\tikzlastnode.south west) + (1.4pt,1.4pt)$)
rectangle
($(\tikzlastnode.north east) - (1.4pt,1.4pt)$)
}},
}
\begin{document}
\begin{tikzpicture}
\node [cvertex, pat1] at (0,0) {};
\node [cvertex, pat2] at (0.3,0) {};
\end{tikzpicture}
\end{document}


Although I still don't understand how it works, using \pgfextra+\endpgfextra commands surrounding append after command paths helps.

\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{calc}
\tikzset{
cvertex/.style={solid, circle, draw=black,line width=1 pt, inner sep=2pt},
local edge style/.style = {line width=1pt, line cap=round, shorten <=2pt, shorten >=2pt},
pat1/.style = {append after command={
\pgfextra
\draw (\tikzlastnode.west)
edge[local edge style]
(\tikzlastnode.east);
\endpgfextra
}},
pat2/.style = {append after command={\pgfextra \draw[line width=1pt]
($(\tikzlastnode.south west) + (1.4pt,1.4pt)$)
rectangle
($(\tikzlastnode.north east) + (-1.4pt,-1.4pt)$);
\endpgfextra
}},
}
\begin{document}
\begin{tikzpicture}
\node [cvertex, pat1] at (0,0) {};
\node [cvertex, pat2] at (0.5,0) {};
\end{tikzpicture}
\end{document}


Update:

With previous solution those inside node decorations won't survive to a fill option, so I provide a better one based in path picture:

\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{calc}
\tikzset{
cvertex/.style={solid, circle, draw=black,line width=1 pt, inner sep=2pt},
local edge style/.style = {line width=1pt, line cap=round, shorten <=2pt, shorten >=2pt, blue},
pat1/.style = {path picture={
\draw (path picture bounding box.west)
edge[local edge style]
(path picture bounding box.east);
}},
pat2/.style = {path picture={\draw[line width=1pt,local edge style]
($(path picture bounding box.south west) + (1.8pt,1.8pt)$)
rectangle
($(path picture bounding box.north east) + (-1.8pt,-1.8pt)$);
}},
}
\begin{document}
\begin{tikzpicture}
\node [cvertex, pat1, draw=red, fill=green] at (0,0) {};
\node [cvertex, pat2, fill=red] at (0.5,0) {};
\end{tikzpicture}
\end{document}