tikz——如何在两个彼此对角线的节点周围创建矩形?

tikz——如何在两个彼此对角线的节点周围创建矩形?

我想要一个包围 A、AC 和 C 的矩形,就像包围 B、BC 和 C 的黄色矩形一样(我同样想要一个包围 A、AB 和 B 的矩形),但我找不到任何方法。当我像对 B、BC 和 C 所做的那样尝试时,矩形变得很大

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{shapes,backgrounds,shapes.misc, positioning,shapes.geometric,arrows,matrix,fit,calc}
    \tikzset{
    buffer/.style={
        isosceles triangle,
        isosceles triangle apex angle=66,
        shape border rotate=90,
        fill=blue!20,
        node distance=5cm,
        rounded corners=60pt,
        opacity=0.6,
        minimum height=6cm
    }
}
\begin{document} 

\begin{tikzpicture}

 \tikzset{venn circle/.style={draw,circle,minimum width=9mm,fill=#1,opacity=0.6}}

\node at (0,0) {A};
\node (ABC) at (0,-2        ) {ABC};
\node (B) at (-2,-3) {B};
\node (AB) at (-1,-1.5) {AB};
\node (AC) at (1,-1.5) {AC};
\node (BC) at (0,-3) {BC};
\node (C) at (2,-3) {C};

\node[buffer]at (0,-1.9){};

\node[draw, thick, rounded corners = 2.5ex, fit=(B) (C),inner sep=3mm, opacity =    0.6, fill = yellow](FIt1) {};

\node[venn circle = green, thick] at (0,0) {A};
\node (ABC) at (0,-2        ) {ABC};
\node[venn circle = green, thick] (B) at (-2,-3) {B};
\node (AB) at (-1,-1.5) {AB};
\node (AC) at (1,-1.5) {AC};
\node (BC) at (0,-3) {BC};
\node[venn circle = green, thick]  (C) at (2,-3) {C};

\end{tikzpicture}
\end{document}

我的尝试

我有一个子问题是,是否可以在这里画一条轮廓线,在黄色、红色和蓝色形状周围画一条黑线

\begin{tikzpicture}[font=\sffamily\sansmath]

 \tikzset{venn circle/.style={circle,minimum width=9mm,fill=#1,opacity=0.6}}

\node at (0,0) {A};
\node (ABC) at (0,-2        ) {ABC};
\node (B) at (-2,-3) {B};
\node (AB) at (-1,-1.5) {AB};
\node (AC) at (1,-1.5) {AC};
\node (BC) at (0,-3) {BC};
\node (C) at (2,-3) {C};


\node[buffer]at (0,-1.9){};



\draw [line width=35pt,opacity=0.6,blue,line cap=round,rounded corners] (A.center) -- (AC.center) -- (C.center);
\draw [line width=35pt,opacity=0.6,yellow,line cap=round,rounded corners] (C.center) -- (BC.center) -- (B.center);
\draw [line width=35pt,opacity=0.6,red,line cap=round,rounded corners] (A.center) -- (AB.center) -- (B.center);



\node[venn circle = green, thick] at (0,0) {A};
\node (ABC) at (0,-2        ) {ABC};
\node[venn circle = green, thick] (B) at (-2,-3) {B};
\node (AB) at (-1,-1.5) {AB};
\node (AC) at (1,-1.5) {AC};
\node (BC) at (0,-3) {BC};
\node[venn circle = green, thick]  (C) at (2,-3) {C};


\end{tikzpicture}

答案1

我得到了以下图片:

在此处输入图片描述

为此,我大大减少了您的代码,看看这对您是否有用。

\documentclass{article}
\usepackage{tikz}

    \usetikzlibrary{arrows,backgrounds,calc,fit,matrix,positioning,
                    shapes,shapes.geometric,shapes.misc}
\pgfdeclarelayer{foreground} 
\pgfdeclarelayer{background}
   \pgfsetlayers{background,%
                 main,%
                 foreground%
                 }

\begin{document}
    \begin{tikzpicture}[
venn circle/.style = {circle, draw, thick, fill=#1,
                      minimum width=9mm, opacity=0.6},
     buffer/.style = {
        isosceles triangle,
        isosceles triangle apex angle=66,
        shape border rotate=90,
        fill=blue!20, opacity=0.6,
        node distance=5cm,
        rounded corners=60pt,
        minimum height=6cm},
frames/.style args = {#1/#2}{minimum height=#1,
               minimum width=#2+\pgfkeysvalueof{/pgf/minimum height},
               draw, rounded corners=5mm, fill=yellow, opacity=0.6,
               sloped}, 
                        ]
    \begin{pgfonlayer}{foreground}
\node (A) [venn circle = green]  at (0,0)    {A};
\node (B) [venn circle = green]  at (-2,-3)  {B};
\node (C) [venn circle = green]  at (2,-3)   {C};
\node (ABC) at (0,-2) {ABC};
\node (AB) at (-1,-1.5) {AB};
\node (AC) at (1,-1.5) {AC};
\node (BC) at (0,-3) {BC};
    \end{pgfonlayer}
    \begin{pgfonlayer}{main}
\path   let \p1 = ($(C.center)-(A.center)$),
            \n1 = {veclen(\y1,\x1)} in
            (A) -- 
            node[frames=11mm/\n1] {} (C);
\path   let \p1 = ($(B.center)-(C.center)$),
            \n1 = {veclen(\y1,\x1)} in
            (B) --
            node[frames=11mm/\n1] {} (C);
    \end{pgfonlayer}
    \begin{pgfonlayer}{background}
\node[buffer]at (0,-1.9){};
    \end{pgfonlayer}
\end{tikzpicture}
\end{document}

编辑:在我的第一个版本中,我没有抓住问题的重点。感谢@Alenanno 指出这一点,我重新进行了回答(尽管这个问题可能是重复的......它至少是我的练习 :-)

相关内容