0

In TikZ, for some node (x), one can use e.g. (x.west) to refer to anchors of the node x. If I try to by hand define a coordinate with a "." in the name, this doesn't work:

\coordinate (x.test) at (4,0);

Is there any way to define a coordinate such that (x.text) refers to this coordinate?

2
  • 1
    You can define your own shape in which test is an anchor.
    – user194703
    Dec 5 '19 at 15:21
  • 3
    Other than that I really do not think there is any reasonable possibility. You cannot have points, commas, parentheses, square brackets, dollar signs and so on in node names without causing trouble.
    – user194703
    Dec 5 '19 at 15:42
2

You are asking

Is there any way to define a coordinate such that (x.text) refers to this coordinate?

Technically, there is. You could redefine (locally I hope) the coordinate shape to have a test anchor.

\documentclass[tikz,border=3mm]{standalone}
\begin{document}
\begin{tikzpicture}
\makeatletter
\pgfdeclareshape{coordinate}
{
\savedanchor\centerpoint{%
\pgf@x=.5\wd\pgfnodeparttextbox%
\pgf@y=.5\ht\pgfnodeparttextbox%
\advance\pgf@y by -.5\dp\pgfnodeparttextbox%
}
\anchor{center}{\centerpoint}
\anchor{test}{\centerpoint}
\anchorborder{\centerpoint}
}
\makeatother
\coordinate (x) at (4,0);
\draw (x.test) -- ++ (1,1);
\end{tikzpicture}
\end{document}

However, I do not recommend at all using this or similar constructions. Rather, I'd like to argue it is much better to accept the fact that you cannot have points, commas, parentheses, square brackets, braces (that get interpreted as such), ~, plain dollar signs, plain #s, plain pipes, plain %, ampersands and perhaps a few more do not work. (Depending on the packages you load, this list may get longer anyway.) Personally I am really amazed by the fact that e.g. spaces and underscores do work. Having these special characters makes is very convenient to deal with TikZ. If you wanted to allow . then there will either be ambiguities, or you would have to forbid users to use (node.north) to refer to the north anchor.

5
  • Thanks! What I'm actually searching for is an easy way to make custom node shapes without having to go to low-level pgf. So far I'm using TeX commands that do the drawing in TikZ, and was looking for a way to mimick node anchors. Is your example above the shortest way to define a shape without drawing, but only anchors?
    – Andi Bauer
    Dec 6 '19 at 10:26
  • @AndiBauer I copied the definition of the coordinate shape and added an anchor, so it might be the shortest way. But I do not yet understand the purpose of this. Why precisely do you want to have these anchors or coordinate names that contain a period?
    – user194703
    Dec 6 '19 at 14:28
  • I want to be able to place complicated shapes and connect them by lines. Defining custom node shapes seems too cumbersome though. So I use nodes with predefined shapes for the simpler shapes, and TeX commands for more complicated ones. These TeX commands automatically define coordinates with names like "node1*west". It would be nice to be able to access these fake anchors in the same way as the real node anchors.
    – Andi Bauer
    Dec 6 '19 at 14:39
  • @AndiBauer Maybe you are looking for pics? They allow you to draw shapes in a very simple way, and refer to predefined coordinates from outside.
    – user194703
    Dec 6 '19 at 14:41
  • That sounds promising, will check that out!
    – Andi Bauer
    Dec 6 '19 at 14:43

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.