4

I would to define a new "T" shape (i.e. the red and green shapes in the following image) so that I can then draw with TikZ the diagram below.

component

Unfortunately I cannot figure out how to do. To be honest, I have read the section "Declaring New Shapes" from the PGF manual and I am completely lost with the low level pgf commands.

How could I do? Suggestions on any direction are welcomed.

  • 1
    Easier reading might be makeshape. – Andrew Swann Aug 20 '13 at 15:31
  • 1
    Can you use an -| arrow, e.g. \draw [-|] (0,0) -- +(0,1);? – Torbjørn T. Aug 20 '13 at 15:48
  • @AndrewSwann Cool I didn't know that. Cannot access it now either but still cool :) – percusse Aug 20 '13 at 17:09
  • @TorbjørnT, I tried but it seems that I don't get a T shape as expected. – Laurent Aug 20 '13 at 18:57
  • What do you get? How much of a T it is depends on the length of the line I guess. – Torbjørn T. Aug 20 '13 at 19:01
7

Finally, I have succeeded to create a "T" shape by adapting existing examples on the Web. Below is the pgf code to define the shape.

\makeatletter
\pgfdeclareshape{t}{
    \inheritsavedanchors[from=rectangle]
    \inheritanchorborder[from=rectangle]
    \inheritanchor[from=rectangle]{center}
    \inheritanchor[from=rectangle]{base}
    \inheritanchor[from=rectangle]{north}
    \inheritanchor[from=rectangle]{north east}
    \inheritanchor[from=rectangle]{east}
    \inheritanchor[from=rectangle]{south east}
    \inheritanchor[from=rectangle]{south}
    \inheritanchor[from=rectangle]{south west}
    \inheritanchor[from=rectangle]{west}
    \inheritanchor[from=rectangle]{north west}
    \backgroundpath{
        % store lower right in xa/ya and upper right in xb/yb
       \southwest \pgf@xa=\pgf@x \pgf@ya=\pgf@y
       \northeast \pgf@xb=\pgf@x \pgf@yb=\pgf@y
       \pgfmathparse{(\pgf@xb-\pgf@xa)/2}
       \pgf@xc=\pgf@xa
       \advance\pgf@xc by \pgfmathresult pt
       \pgfpathmoveto{\pgfpoint{\pgf@xa}{\pgf@ya}}
       \pgfpathmoveto{\pgfpoint{\pgf@xa}{\pgf@yb}}
       \pgfpathlineto{\pgfpoint{\pgf@xb}{\pgf@yb}}
       \pgfpathmoveto{\pgfpoint{\pgf@xc}{\pgf@yb}}
       \pgfpathlineto{\pgfpoint{\pgf@xc}{\pgf@ya}}
   }
}
\makeatother

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.