0

Consider the following MWE:

\documentclass[border=1cm]{standalone}
\usepackage{tikz}

\tikzset{
    first/.style = {
        draw,
        ultra thick,
        red,
    },
    second/.style = {
        draw,
        ultra thin,
        blue,
        >=latex,
        ->
    }
}

\makeatletter

\pgfdeclareshape{symbol}{
  \savedanchor{\southwest}{\pgfpoint{-0.5cm}{-0.5cm}}
  \savedanchor{\northeast}{\pgfpoint{0.5cm}{0.5cm}}
  \inheritanchorborder[from=rectangle]
  \anchor{north}{\pgfpoint{0}{0.25cm}}
  \inheritanchor[from=rectangle]{east}
  \anchor{south}{\pgfpoint{0}{-0.25cm}}
  \inheritanchor[from=rectangle]{west}
  \inheritanchor[from=rectangle]{center}
  \anchor{inner east}{\pgfpoint{0.5cm - 0.4pt}{0}}
  \anchor{text}{\pgfpoint{-.5\wd\pgfnodeparttextbox}{-.5\ht\pgfnodeparttextbox+.5\dp\pgfnodeparttextbox}}

  \backgroundpath{
    \pgfkeys{/tikz/.cd, first}

    \pgfpathmoveto{\pgfpoint{-0.5cm + \pgfkeysvalueof{/pgf/outer xsep} }{0.5cm - (0.5 + sqrt(1.25))*\pgfkeysvalueof{/pgf/outer ysep} }}
    \pgfpathlineto{\pgfpoint{0.5cm - sqrt(5)*\pgfkeysvalueof{/pgf/outer xsep} }{0}}
    \pgfpathlineto{\pgfpoint{-0.5cm + \pgfkeysvalueof{/pgf/outer xsep} }{-0.5cm + (0.5 + sqrt(1.25))*\pgfkeysvalueof{/pgf/outer ysep} }}
    \pgfpathclose

    \pgfkeys{/tikz/.cd, second}
    \pgfpathmoveto{\pgfpoint{-0.25cm}{-0.5cm}}
    \pgfpathlineto{\pgfpoint{0.25cm}{0.5cm}}
  }
}


\makeatother

\begin{document}
    \begin{tikzpicture}
        \node (a) at (0,0) [symbol] {};
    \end{tikzpicture}
\end{document}

this is what is produced with the above code:

enter image description here

I expect to be able to configure the appearance of the triangle and the line individually with my two individual TikZ styles. So, I actually would expect the triangle to be ultra thick and red, and the single straight line should be ultra thin, blue and equipped with an arrow.

Why is this not the case, and what shall I change? I already tried \pgfusepath{stroke} with no effect.

  • How would that work? You'd need to fill these directives into \pgfsetlinewidth etc. If that was not the case, you'd mess up decorations by saying dashed before. – marmot Oct 24 '18 at 18:10
  • 1
    One more thing: you cannot change colors in a path. That is, you'd need to say something like \pgfusepath{stroke} before switching to a new color. There are, of course, good reasons, not to cut the path to pieces (e.g. if you want to fill the region in between). I really think you should have a look at pics and/or path picture, which allow you to do these things. – marmot Oct 24 '18 at 18:34
  • Obviously it works, but I don't understand all internal workings yet, that's true. Actually I wanted to use PGF shapes because these are exactly designed for what I am planning to do. I had previously some path pictures, but there it is also possible to mess things up with some styles. – T. Pluess Oct 24 '18 at 19:19

Your Answer

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

Browse other questions tagged or ask your own question.