The problem can be fixed by using a preaction
/postaction
style. These styles you can read about in the manual. Basically it takes the current path and does something to it.
What you then can do is:
\tikzset{add shifted/.style={%
postaction={%
transform canvas={%
xshift=0.1cm,yshift=-0.1cm
},draw,fill=white,#1%
}%
}}
This will make a shifted drawing after (hence postaction
), which is filled with white and drawn as specified.
You can also do it the other way around with preaction
. I have here shown how it could be done with a couple of different techniques. Also you can toy with this and nodes, remember that nodes are also paths (rectangular paths if not specified).
\documentclass{article}
\usepackage{tikz}
\begin{document}
\tikzset{%
my box/.style={draw,fill=white},
% Shifted without need for correct middle coordinate
add shifted/.style={%
postaction={%
transform canvas={%
xshift=0.1cm,yshift=-0.1cm
},my box,#1%
}%
},
% Shifted with need for correct middle coordinate
add left/.style={%
preaction={%
transform canvas={%
xshift=-0.1cm,yshift=0.1cm
},my box,#1%
}%
},
add right/.style={%
postaction={%
transform canvas={%
xshift=0.1cm,yshift=-0.1cm
},my box,#1%
}%
},
% Both left and right collected to one, with separate args.
add lr/.style 2 args={add left={#1},add right={#2}},
% A style which also adds text. (not so agile)
add lr text/.style={add left,add right,postaction={%
transform canvas={yshift=-0.5cm},
path picture={%
\node[anchor=south] at (path picture bounding box.south) {#1};%
}%
}%
}
}
\begin{tikzpicture}
\path[use as bounding box] (-0.5,-0.75) rectangle (8.5,2.5);
\draw[my box,add shifted={add shifted=add shifted}] (0,0) rectangle ++(2,2);
\node[below=6pt] at (1.25,0) {Text};
\draw[my box,add lr={fill=brown}{fill=yellow}] (3,0) rectangle ++(2,2);
\node[below] at (4,0) {Text};
\draw[my box,add lr text=Text] (6,0) rectangle ++(2,2);
\end{tikzpicture}
\end{document}
Which will output as:

You can of course adapt to your needs.
Notice that you can keep tweaking your styles until you basically only need to alter one input.