在陰影上使用擬合節點以包含陰影

在陰影上使用擬合節點以包含陰影

我使用了雙重複製陰影(來自這個答案) 將多個矩形新增至一個節點。我現在想用一個適合節點包裹該節點和其他幾個節點,但看起來適合節點不包括陰影。

例如:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{shadows,positioning,calc,fit}
\tikzset{multiple/.style = {double copy shadow={shadow xshift=1ex,shadow
         yshift=-1.5ex,draw=black!30},fill=white,draw=black,thick,minimum height = 1cm,minimum
           width=2cm},
         ordinary/.style = {rectangle,draw,thick,minimum height = 1cm,minimum width=2cm}}

\begin{document}
\begin{tikzpicture}
   \node [ordinary] at (0,0) (a) {Some};
   \node [multiple,below=3cm of a] (b) {Text};
   \draw[-latex] (a) -- coordinate (ab) (b);
   \draw (ab) -- ++(0.7,-0.5)coordinate[pos=.3](ab1) coordinate[pos=.6](ab2);
   \draw[-latex] (ab1) -- ($(b.north west)!(ab1)!(b.north east)$);
   \draw[-latex] (ab2) -- ($(b.north west)!(ab2)!(b.north east)$);

   \node [fit=(a)(b),draw,rectangle] {};
\end{tikzpicture}
\end{document}

結果是:

渲染範例

是否可以更改程式碼以包含它們?

答案1

如果已知由於陰影導致的佔用率增加,則可以定義fit shadow增加的樣式x|y sep以包含陰影。

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{shadows,positioning,calc,fit}
\tikzset{%
multiple/.style = {%
    double copy shadow={%
        shadow xshift=1ex, 
        shadow yshift=-1.5ex, 
        draw=black!30},
    fill=white, 
    draw=black,
    thick,
    minimum height = 1cm,
    minimum width=2cm},
ordinary/.style = {%
    rectangle,
    draw,
    thick,
    minimum height = 1cm,
    minimum width=2cm},
fit shadow/.style = {%
    fit = #1,
    inner xsep=2ex+.3333em,
    inner ysep=3ex+.3333em}
}

\begin{document}
\begin{tikzpicture}
   \node [ordinary] at (0,0) (a) {Some};
   \node [multiple, below=3cm of a] (b) {Text};
   \draw[-latex] (a) -- coordinate (ab) (b);
   \draw (ab) -- ++(0.7,-0.5)coordinate[pos=.3](ab1) coordinate[pos=.6](ab2);
   \draw[-latex] (ab1) -- ($(b.north west)!(ab1)!(b.north east)$);
   \draw[-latex] (ab2) -- ($(b.north west)!(ab2)!(b.north east)$);

   \node [fit shadow=(a)(b), draw, rectangle] {};
\end{tikzpicture}
\end{document}

在此輸入影像描述

作為替代方案,也可以在fit清單中包含所需的陰影角:

\node [fit={(a)([shift={(2ex,-3ex)}]b.south east)}, draw, rectangle] {};

在此輸入影像描述

相關內容