I wish to use pgfdeclareshape draw a file archive shape.
\documentclass[border=2pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{calc}
\makeatletter
\pgfdeclareshape{mrects}{
\inheritsavedanchors[from=rectangle]
\inheritanchorborder[from=rectangle]
\inheritbackgroundpath[from=rectangle]
\foreach \i in {center,north,south,east,west} {
\inheritanchor[from=rectangle]{\i}
}
\anchor{text} {
\pgfpoint{-0.5\wd\pgfnodeparttextbox}{-0.5\ht\pgfnodeparttextbox}
}
\backgroundpath{
% store lower right in xa/ya and upper right in xb/yb
\southwest \pgf@xa=\pgf@x \pgf@ya=\pgf@y
\northeast \pgf@xb=\pgf@x \pgf@yb=\pgf@y
% construct main path
\pgfpathmoveto{\pgfpoint{\pgf@xa}{\pgf@ya}}
\pgfpathlineto{\pgfpoint{\pgf@xa}{\pgf@yb}}
\pgfpathlineto{\pgfpoint{\pgf@xb}{\pgf@yb}}
\pgfpathlineto{\pgfpoint{\pgf@xb}{\pgf@ya}}
\pgfpathclose
% my code
\newdimen\pgf@xd
\newdimen\pgf@yd
\newdimen\pgf@xe
\newdimen\pgf@ye
\newdimen\pgf@xg
\newdimen\pgf@yg
\newdimen\pgf@xh
\newdimen\pgf@yh
%
\pgf@xg=\pgf@xa
\pgf@yg=\pgf@yb
\pgf@xh=\pgf@xb
\pgf@yh=\pgf@ya
\foreach \i [evaluate=\i as \j using int(\i*2)] in {1,...,2} {
\pgf@xd=\pgf@xg \advance\pgf@xd by \j pt
\pgf@yd=\pgf@yg \advance\pgf@yd by \j pt
\pgf@xe=\pgf@xh \advance\pgf@xe by \j pt
\pgf@ye=\pgf@yh \advance\pgf@ye by \j pt
% add line
\pgfpathmoveto{\pgfpoint{\pgf@xd}{\pgf@yg}}
\pgfpathlineto{\pgfpoint{\pgf@xd}{\pgf@yd}}
\pgfpathlineto{\pgfpoint{\pgf@xe}{\pgf@yd}}
\pgfpathlineto{\pgfpoint{\pgf@xe}{\pgf@ye}}
\pgfpathlineto{\pgfpoint{\pgf@xh}{\pgf@ye}}
\pgf@xg=\pgf@xd
\pgf@yg=\pgf@yd
\pgf@xh=\pgf@ye
\pgf@yh=\pgf@ye
}
}
\foregroundpath{
\pgfusepath{stroke}
}
}
\makeatother
\begin{document}
\begin{tikzpicture}
\node[draw,mrects,minimum width=6em,minimum height=2em] (N1) {hello world};
\end{tikzpicture}
\end{document}
But two issues need your help:
- The text not at the center.
- The
north westandsouth eastcorner lines crossed together.sounds line the assignment at the end offoreachloop doesn't work.


\foreachloop in a shape declaration. If you use the thing in another foreach loop over\iyou will get even more surprised than you already are. – Jan 11 '19 at 19:23double copy shadow, which seem to do what you like to achieve ... – Zarko Jan 11 '19 at 19:25