# tikz shape fill not working

I am trying to define a shape as the attached yellow filled one. However, when I place the lines inside, the fill does not work properly and the rectangle's green background shows through. I have two questions:

1) How can I fix this in the code below? 2) Is there a way to define this as a shape that I can use as a regular shape? I am afraid I don't know tikz or pgf sufficiently to be able to do that.

Any assistance would be greatly appreciated.

\documentclass{minimal}
\usepackage{tikz}
\usetikzlibrary{shapes,positioning}

\begin{document}
\begin{tikzpicture}

\node$rectangle,draw,fill=green,minimum width=1cm,minimum height=1cm$ (test) at (0,0) {};
\draw$fill=yellow$ (0,0) -- (0,0.6) -- (0.4,0.6) -- (0.4,0) -- (0.2,-0.1) -- (0,0) -- cycle
(0,0.2) -- (0.2,0.15) -- (0.4,0.2)
(0,0.4) -- (0.2,0.35) -- (0.4,0.4)
node (ar1) {};

\end{tikzpicture}
\end{document}


• Kindly correct your editor so that next time you don't post code with spurious characters like the one in \[ and ![\documentclass{minimal} and don't use minimal class. – user11232 Aug 15 '14 at 1:53

I don't advice beginners to venture in to the jungle of defining new shapes using pgf (low level of tikz). You can draw the shape instead and re-use it using pic facility provided by tikz version 3. Though I don't claim to have understood your needs properly, here is an attempt using pic:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{shapes,positioning}

\tikzset{
myshape/.pic={
code={
\draw[fill=yellow] (0,0) -- (0,0.6) -- (0.4,0.6) -- (0.4,0) -- (0.2,-0.1) -- (0,0)
-- cycle;
\draw (0,0.2) -- (0.2,0.15) -- node[pos=0.1,above=-0.7ex,font=\tiny] (ar1) {fg}(0.4,0.2);
\draw (0,0.4) -- (0.2,0.35) -- (0.4,0.4);
}}
}

\begin{document}
\begin{tikzpicture}
\node[rectangle,draw,fill=green,minimum width=1cm,minimum height=1cm] (test) at (0,0) {};
\path (0,0) pic {myshape};
\end{tikzpicture}
\end{document}


• Thanks much. This may do for now. I was hoping that I could define it as a shape so that I can declare a node to be of that shape and position it relative to another shape (e.g., above the rectangle node) rather than absolute positioning. I suppose that requires more machinery!... – ozsu Aug 15 '14 at 2:06
• @ozsu That require some pgf code. This site has some examples though if you search for example: Making a PGF shape. – user11232 Aug 15 '14 at 2:12
• Thanks much. This will do for now. I will spend time learning pdf a bit more when I get a chance. – ozsu Aug 15 '14 at 3:08