2

Following this lovely answer, we are able to make anchor aliases: https://tex.stackexchange.com/a/14772/186406

Are we able to make an anchor alias that is equivalent to not passing an anchor to the node at all? Let's say I define an anchor as d (default), I want:

\documentclass[tikz,border=2mm]{standalone}

\begin{document} \begin{tikzpicture} \node[circle, draw, label=A] (A) at (0,1) {}; \node[circle, draw, label=B] (B) at (1,0) {}; \draw[<->] (A) -- (B); % node to node line \draw[<->] (A.d) -- (B.d); % this should be the same as above \end{tikzpicture} \end{document}

  • 2
    Not without rewriting TikZ's node parser. But that can be done easily. (Though, it might break at some other point where we don't expect it.) … Why? – Qrrbrbirlbel Nov 22 '23 at 15:46
  • I'm making a macro for overlaying captions+arrows and I would like an option for how the captions node anchor connects to an arrow. Rather than writing in some logic to accommodate this, defining a node anchor seemed that it could be simpler at first glance. – likethevegetable Nov 22 '23 at 15:57
  • 1
    Could you say why you can't just not specify an anchor? I'm guessing this is because you want to use this in a macro definition of some kind. If so, you could just use a conditional to specify an anchor (if given) or not (if not). But that's presumably too simplistic. – cfr Nov 22 '23 at 16:51
  • 2
    With the explicit node cs specification you can use (node cs: name=A, anchor=none) -- (node cs: name=B, angle=none). [Both anchor and angle are preset with none, so (node cs: name=A) -- (node cs: name=B) would be the normal way to specify this connection.] This is one way to not have to check yourself whether a user has specified a special non-anchor anchor. – Qrrbrbirlbel Nov 22 '23 at 17:56
  • @cfr it's simply a matter of improving the command interface and my code. I have a list of key-vals (one key being anchor=) and just wanted to avoid re-writing a line of code where I would have to check if the passed value for anchor was d. Of course this is easy and I have it working, but I try to avoid conditionals and re-writing similar lines of code if necessary, – likethevegetable Nov 22 '23 at 18:06
  • I was thinking more in terms of \NewDocumentCommand, but you could have a key set a macro to dot + argument, say, where the macro is empty by default and then use <name>\macro in place of <name>.d (depending on whether that would work in the relevant cases). It needn't mean maintaining near-duplicate lines of code. – cfr Nov 22 '23 at 18:38

0 Answers0