如何使用“适合”使三角形紧密(无空间)包围其他三角形?

如何使用“适合”使三角形紧密(无空间)包围其他三角形?

我正在尝试将几个三角形围成一个更大的三角形,而不在它们之间留任何空间,但迄今为止结果都是负面的。

输出(我手工绘制的绿色虚线;这是我需要放置封闭三角形的位置):

代码:

\documentclass[border=5mm]{standalone}

\usepackage{tikz}

\usetikzlibrary
{%
    fit,
    positioning,
    shapes.geometric
}

\tikzset{every picture/.style={line width=1pt}}

\begin{document}

    \begin{tikzpicture}
        [%
            every isosceles triangle node/.style=
            {%
                inner sep=0mm,
                outer sep=0mm,
                isosceles triangle apex angle=60
            }
        ]%

        % TOP TRIANGLE
        \path node
            [%
                isosceles triangle,
                shape border rotate=90,
                draw=red,fill=red!20,
                minimum size=20mm
            ]   (T1){};

        % BOTTOM TRIANGLE
        %  (ALIGNED TO TOP TRIANGLE'S LEFT CORNER)
        \path node
            [%
                isosceles triangle,
                shape border rotate=90,
                below=0mm of T1.left corner,
                anchor=apex,
                draw=red,fill=red!20,
                minimum size=20mm
            ]   (T2){};

        % ENCLOSING TRIANGLE
        \path node
            [%
                isosceles triangle,
                shape border rotate=90,
                line width=0pt,
                draw,
                fit=(T1)(T2)
            ]   (ENCLOSURE){};

    \end{tikzpicture}

\end{document}

答案1

小变化:

  • 使用fit=(T1.north east)(T2.south east)而不是fit=(T1)(T2)
  • 选项:dashed,thick,green,-> 绿色虚线

或者留出一些空间:

  • \usepackage{calc}-> 相对坐标
  • 例如 (border = 0.05): 更改fitfit={($(T1.north east)+(0.05,0)$)($(T2.south east)+(-0.05,-0.05)$)}

结果:

在此处输入图片描述

梅威瑟:

\documentclass[border=5mm]{standalone}

\usepackage{tikz}
\usetikzlibrary
{%
    fit,
    positioning,
    shapes.geometric,
    calc
}
%\tikzset{every picture/.style={line width=1pt}}
\begin{document}
    \begin{tikzpicture}
        [%
            every isosceles triangle node/.style=
            {%
                inner sep=0mm,
                outer sep=0mm,
                isosceles triangle apex angle=60
            }
        ]%

        % TOP TRIANGLE
        \path node
            [%
                isosceles triangle,
                shape border rotate=90,
                draw=red,fill=red!20,
                minimum size=20mm
            ]   (T1){};
        % BOTTOM TRIANGLE
        %  (ALIGNED TO TOP TRIANGLE'S LEFT CORNER)
        \path node
            [%
                isosceles triangle,
                shape border rotate=90,
                below=0mm of T1.left corner,
                anchor=apex,
                draw=red,fill=red!20,
                minimum size=20mm
            ]   (T2){};
        % ENCLOSING TRIANGLE
        \path node
            [%
                isosceles triangle,
                shape border rotate=90,
                line width=0pt,
                draw,
                dashed,thick,green,
                %fit=(T1.north east)(T2.south east)
                fit={($(T1.north east)+(0.05,0)$)($(T2.south east)+(-0.05,-0.05)$)}
            ]   (ENCLOSURE){};
    \end{tikzpicture}
\end{document}

相关内容