tikz 自定义文件存档形状

tikz 自定义文件存档形状

我希望使用 pgfdeclareshape 绘制文件存档形状。

\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}

在此处输入图片描述

但有两个问题需要你的帮助:

  1. 文字不在中心。
  2. north west和角线south east交叉在一起。循环末尾的声音线foreach分配不起作用。

答案1

正如 Zarko 指出的那样,double copy shadow解决了您的问题:

\documentclass[border=2mm, tikz]{standalone}
\usepackage{tikz}
\usetikzlibrary{shadows}

\begin{document}
    \begin{tikzpicture}
    \node[double copy shadow,
        fill=white,
        draw=black,
        minimum width=6em,
        minimum height=2em] (N1) {Hello World};
    \end{tikzpicture}
\end{document}

在此处输入图片描述

相关内容