5

I am trying, so far with negative result, to enclose a couple of triangles in a bigger triangle without leaving any space between them.

Output (dashed green line I drew by hand; this is where I need the enclosing triangle to be positioned at):

Code:

\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}
  • 2
    try fit=(T1.north east)(T2.south east) – Bobyandbob Sep 5 '17 at 8:29
5

Small Changes:

  • use fit=(T1.north east)(T2.south east) instead of fit=(T1)(T2)
  • option: dashed,thick,green, -> green and dotted line

Or with some space:

  • \usepackage{calc} -> for relative coordinates
  • for example (border = 0.05): change fit to fit={($(T1.north east)+(0.05,0)$)($(T2.south east)+(-0.05,-0.05)$)}

Result:

enter image description here

MWE:

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.