2

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}

enter image description here

1
  • 2
    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
    Commented Aug 15, 2014 at 1:53

1 Answer 1

2

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}

enter image description here

3
  • 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
    Commented Aug 15, 2014 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
    Commented Aug 15, 2014 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
    Commented Aug 15, 2014 at 3:08

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .