2

I want to combine two objects, so that only the outer border is displayed. Additionally, I want to reuse the second object several times. See here my example code:

\documentclass[class=tufte-book]{standalone}
\usepackage{tikz,pgfplots}
    \usetikzlibrary{colorbrewer}

\begin{document}
    \begin{tikzpicture}
        \newsavebox{\test}
        \savebox{\test}{
            \begin{tikzpicture}
                \draw[fill=PuBuGn-9-1] (-1, 0.0) -- (-1,-1) -- (1,-1) -- (1,0);
            \end{tikzpicture}
        }

        \draw[fill=PuBuGn-9-1] (-1,-2) -- (3, -1) -- (4, 2) -- (2,3)  -- (-1,-2);
        \node[rotate=60] at (3,-0.5){\usebox{\test}};

    \end{tikzpicture}
\end{document}

The result of this code is this picture (the border of both objects is the same, it looks different because of the jpeg compression):

Not combined

But I'd like to have this kind of result:

Combined

Is that possible? Because calculating the cross-section would be difficult... Thank you very much.

3

Here is one idea (first draw then fill).

\documentclass{standalone}
\usepackage{tikz}

\tikzset{
    path1/.style={
        insert path={(-1,-2) -- (3, -1) -- (4, 2) -- (2,3)  -- (-1,-2)}
    },
    path2/.style={
        insert path={(-1, 0.0) -- (-1,-1) -- (1,-1) -- (1,0)}
    }
}

\begin{document}
    \begin{tikzpicture}
        % first draw
        \begin{scope}[thick]
            \draw[path1];
            \draw[rotate=60, shift={(1,-2.4)}][path2];
        \end{scope}
        % then fill
        \begin{scope}[red!30]
            \fill[path1];
            \fill[rotate=60, shift={(1,-2.4)}][path2];
        \end{scope}
    \end{tikzpicture}
\end{document}

enter image description here

|improve this answer|||||

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.