Tikz 适合库包含形状但排除(剪切)其他形状吗?

Tikz 适合库包含形状但排除(剪切)其他形状吗?

下面是使用该fit库在节点 A、B 和 C 周围添加高亮的示例。如果我想排除 D 怎么办?(显然它必须是非矩形形状)

我想我正在寻找一种实现形状的并集/交集/差异的方法。

在此处输入图片描述

\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{shadows,arrows,positioning,fit,backgrounds,shapes,patterns}
\begin{document}
\begin{tikzpicture}[node distance=5mm, auto,
    block/.style={
        % The shape:
        rectangle, minimum size=6mm, minimum height=6mm, minimum width=30mm,
        rounded corners=1mm,
        node distance=8mm,
        % The rest
        thick,draw=black,
        top color=white,
        bottom color=myblue!15,
        font=\sffamily\footnotesize,
        drop shadow
    },
    area/.style={
        rectangle,
        fill=green!80!black, opacity=0.2,
        draw=black
    },
    >=latex
    ]
        \node (a) {A};
        \node [right=of a] (b) {B};
        \node [below=of a] (c) {C};
        \node [right =of c] (d) {D};
        \node [area, fit=(a) (b) (c)] {};   
\end{tikzpicture}
\end{document}

这类似于如何使用 tikz 进行非矩形拟合?但不一样。

答案1

看看以下解决方案是否适合您:

在此处输入图片描述

\documentclass[border=3mm]{standalone}
\usepackage{tikz}
\usetikzlibrary{arrows,backgrounds,fit,patterns,positioning,shadows,shapes}
\begin{document}
    \begin{tikzpicture}[
    node distance=5mm, 
    auto,
every node/.style={inner sep=2mm, minimum size=7mm}
                        ]
\node (a)               {A};
\node (b) [right=of a]  {B};
\node (c) [below=of a]  {C};
\node (d) [right=of c]  {D};
%
\draw[draw=gray, rounded corners, thick, fill=green!80!black, opacity=0.2]
    (a.north) -| (b.south east) -- (c.south east) -| 
    (a.west) |- (a.north);
\end{tikzpicture}
\end{document}

相关内容