tikz 中的堆叠矩形

tikz 中的堆叠矩形

我希望它最终看起来像这样:

在此处输入图片描述

目前,后面的矩形中仍然有文本,我不知道如何在没有文本的情况下使它们具有正确的大小。

\documentclass[
    %draft, % Mit % kommentieren, um Bilder sichtbar zu machen und Links zu aktivieren
    pdftex,
    a4paper,
    oneside,
    parskip,
    numbers=noenddot,
    listof=totoc,
    bibliography=totoc,
    hyperfootnotes=false
]{scrreprt}
\setuptoc{toc}{totoc}
\usepackage{tikz}
\usetikzlibrary{shapes.geometric, arrows}

\begin{document}
\begin{figure}[h]
\centering
\begin{tikzpicture}
    \tikzset{rectangle node/.style={draw, minimum size=1cm}}
    
    \node[rectangle node] (scl) at (0,0) {SCL Contract};
    \node[rectangle node, right of=scl, node distance = 5cm] (ptg){PlainTextGen};
    \node[rectangle node,right of=ptg, node distance = 5cm, align=right] (sol) {Solidity Code \\.sol};
    \node[rectangle node,below of=sol, node distance = 2cm, align=right, on top of=solLib1] (solLib) {Solidity Libraries \\.sol};
    \node[rectangle,draw, align=right,on top of=solLib2] (solLib1) at (10.1,-1.9) {Solidity Libraries \\.sol};
    \node[rectangle,draw, align=right] (solLib2) at (10.2,-1.8) {Solidity Libraries \\.sol};
    
    \draw [->] (scl) -- (ptg);
    \draw [->] (ptg) -- (sol);
    \draw [->] (sol) -- (solLib);
\end{tikzpicture}
\caption{Code Generation Prozess}
\label{fig:CodeGenProzess}
\end{figure}
\end{document}

答案1

像这样?

在此处输入图片描述

double copy shadow对于您来说,使用 shadowsTi很简单Z 库。

无关:对于节点的定位,我将使用positioning库及其 sintay ...=of <node nameY>,它定义节点边界之间的距离:

\documentclass[margin=3mm]{standalone}
\usepackage{tikz}
\usetikzlibrary{arrows.meta,
                positioning,
                shadows}

\begin{document}
    \begin{tikzpicture}[
node distance = 4mm and 8mm,
     N/.style = {draw, fill=white, minimum size=1cm, align=right},
   dcs/.style = {double copy shadow, shadow xshift=2pt, shadow yshift=-2pt},
every edge/.append style = {draw, semithick, -Stealth}
                        ]
\node[N] (scl)  {SCL Contract};
\node[N, right=of scl]  (ptg)       {PlainTextGen};
\node[N, right=of ptg]  (sol)       {Solidity Code \\.sol};
\node[N, below=of sol, 
      dcs]              (solLib)    {Solidity Libraries \\.sol};
%
\draw   (scl) edge (ptg)
        (ptg) edge (sol)
        (sol) edge (solLib);
    \end{tikzpicture}
\end{document}

答案2

或许有点过头了。

这是在背景层上绘图的方法,使用fit库来计算大小,并在底部插入两个矩形。(鸣谢这个答案这使得可以在底部堆栈上进行绘图。

\documentclass{article}
\usepackage{tikz}
\usepackage{xpatch}
\usetikzlibrary{shapes.geometric, arrows, positioning, fit, backgrounds}

% https://tex.stackexchange.com/a/562606/234654
\makeatletter
% similar to env "pgfonlayer", but the latest contents are typeset on
% lowest bottom (on reversed order)

\let\pgfonlayerreversed\pgfonlayer
\let\endpgfonlayerreversed\endpgfonlayer

\xpatchcmd\pgfonlayerreversed
  {\expandafter\box\csname pgf@layerbox@#1\endcsname\begingroup}
  {\begingroup}
  {}{\fail}

\xpatchcmd\endpgfonlayerreversed
  {\endgroup}
  {\endgroup\expandafter\box\csname pgf@layerbox@\pgfonlayer@name\endcsname}
  {}{\fail}


\tikzset{
  on background layer reversed/.style={%
    execute at begin scope={%
      \pgfonlayerreversed{background}%
      \let\tikz@options=\pgfutil@empty
      \tikzset{every on background layer/.try,#1}%
      \tikz@options
    },
    execute at end scope={\endpgfonlayerreversed}
  }
}


\def\StartDrawOnBottomOfLayerStack{%
  \scope\relax
  % patch \path variants to auto insert "\scoped[on lowest layer]"
  % currently \node, \pic, \coordinate, and \matrix are patched
  \let\tikz@path@overlay\tikz@path@overlay@autoscoped
  \let\tikz@path@overlayed\tikz@path@overlayed@autoscoped
}

\def\EndDrawOnTopOfLayerStack{%
  \endscope
}

\def\tikz@path@overlay@autoscoped#1{%
  \let\tikz@signal@path=\tikz@signal@path% for detection at begin of matrix cell
  \pgfutil@ifnextchar<%
    {\tikz@path@overlayed{#1}}
    {\scoped[on background layer reversed] \path #1}}%
\def\tikz@path@overlayed@autoscoped#1<#2>{%
  \scoped[on background layer reversed] \path<#2> #1}%
\makeatother

\begin{document}
\begin{figure}[h]
\centering
\begin{tikzpicture}
    \tikzset{rectangle node/.style={draw, minimum size=1cm}}

    \node[rectangle node, align=right] (sol) {Solidity Libraries \\.sol};

    \node[rectangle node, align=right,below=8mm of sol, fill=white] (solLib) {Supported Libraries \\.sol};

    \StartDrawOnBottomOfLayerStack
        \node [rectangle node, fit=(solLib), inner sep=0, xshift=1mm, yshift=1mm, fill=white] {};
        \node [rectangle node, fit=(solLib), inner sep=0, xshift=2mm, yshift=2mm] {};
    \EndDrawOnTopOfLayerStack

    \draw [->] (sol) -- (solLib);
    
\end{tikzpicture}
\caption{Code Generation Prozess}
\label{fig:CodeGenProzess}
\end{figure}
\end{document}

结果

相关内容