4

I've used the a double copy shadow (from this answer) to add multiple rectangles to a node. I would now like to wrap that node and several others with a fit node, but it seems like the fit node does not include the shadows.

For example:

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

This results with:

rendered example

Is it possible to change the code to include them?

3
  • 1
    I think the best solution would be to somehow add anchors to the shadow, so that it can be added to the fit list. Alternatively, you could define your multiple style to add an empty label (for instance label={[name=\tikzlastnode-shadow,shift={(1cm+2ex,-0.5cm-3ex)}]center:}, and then you add b-shadow in the fit list). I don't see how to easily make it work in the general case. Jul 11, 2017 at 8:07
  • Thanks, this seems to do what I want. I was also wondering how to make sure a matrix cell includes all the shadows, but I guess that's a matter for a different question.
    – haggai_e
    Jul 11, 2017 at 10:54
  • 1
    By default, shadows aren't even in the current bounding box (unless they happen to be because something else is). This is why a standalone image which is cropped will happily exclude shadows. They just aren't there as far as the bounding box is concerned.
    – cfr
    Jul 11, 2017 at 20:28

1 Answer 1

1

If occupancy increase due to shadows is known, it's possible to define a fit shadow style with increased x|y sep to include shadows.

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

enter image description here

As an alternative, it's also possible to include the desired shadow corner in fit list:

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

enter image description here

2
  • Thanks, though I liked the solution with the anchors better because it works automatically even if the shadow turns out to be not at the edge of the fit note.
    – haggai_e
    Jul 12, 2017 at 8:20
  • @haggai_e: It's another manual solution, but you can decide which particular coordinate include inside fit node. I've included an example in my answer.
    – Ignasi
    Jul 12, 2017 at 8:37

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .