2

I am trying to declare a custom pgf shape. I have a problem that I cannot access the east, west, north, south anchors. This works:

\pgfdeclareshape{mixer}{%
  \inheritsavedanchors[from=circle]
  \inheritanchorborder[from=circle]
  \inheritanchor[from=circle]{center}
  \inheritanchor[from=circle]{north}
  \inheritanchor[from=circle]{south}
  \inheritanchor[from=circle]{west}
  \inheritanchor[from=circle]{east}
  \backgroundpath{%
    \pgf@x=\radius
    \pgf@y=\radius
    \centerpoint \pgf@xa=\pgf@x \pgf@ya=\pgf@y
    \pgfpathcircle{\pgfpoint{\pgf@xa}{\pgf@ya}}{\radius}
  }
}

However, as soon as I try to use something like:

\northeast \pgf@xa=\pgf@x \pgf@ya=\pgf@y

or

\north \pgf@xa=\pgf@x \pgf@ya=\pgf@y

I get undefined command. Why is that?

  • because circle shape doesn't have those saved anchors. They are just anchors that are calculated upon call. – percusse Dec 1 '16 at 18:49
  • @percusse is there a way to access them from within \pgfdeclareshape? – user110971 Dec 1 '16 at 22:15
  • No because they don't exist until they are called. You have to define them yourself if need be – percusse Dec 1 '16 at 23:06
  • @user110971 Suggestion: have you looked at TikZ pics? They are kinda like shapes, but much more simple. Declaring new shapes are (I'd say) not for the end-user, but pics are. You can set coordinates inside the pic which behave like node anchors... Maybe it's what you looking for: check this link. – Guilherme Zanotelli Dec 5 '16 at 15:21
3

You still have a chance: the definition of those anchors are hidden in

\pgf@anchor@⟨shape name⟩@⟨anchor name⟩

So \north can be retrieved by

\pgf@anchor@mixer@north

Full code

\documentclass{article}
\usepackage{tikz}

\begin{document}
\makeatletter
\pgfdeclareshape{mixer}{%
  \inheritsavedanchors[from=circle]
  \inheritanchorborder[from=circle]
  \inheritanchor[from=circle]{center}
  \inheritanchor[from=circle]{north}
  \inheritanchor[from=circle]{south}
  \inheritanchor[from=circle]{west}
  \inheritanchor[from=circle]{east}
  \backgroundpath{%
    \centerpoint
    \pgfpathcircle{\pgfpoint{\pgf@x}{\pgf@y}}{\radius}
    \pgfpathmoveto{\pgf@anchor@mixer@east}
    \pgfpathlineto{\pgf@anchor@mixer@north}
    \pgfpathmoveto{\pgf@anchor@mixer@south}
    \pgfpathlineto{\pgf@anchor@mixer@west}
    \pgfusepath{stroke}
  }
}

\tikz\node[mixer]{0123456789};

\end{document}

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.