First, a disclaimer: I cannot believe that I'm the first one asking that, so I probably missed an obvious answer.
We can use anchors to position a node. But after positioning, the default anchor for the node is back to center.
Is there a way to set the default anchor of a node whenever it is referred to (e.g. in calc, or in a path)?
Take for example the case of section 17.5.2 of the manual, but using calc instead of paths:
\begin{tikzpicture}
\begin{scope}[every node/.style={anchor=center}]
\node (x) {x};
\node at ($(x)+(2,0)$) (y) {y};
\node at ($(x)+(4,0)$) (z) {z};
\path[draw,red] (x) -- (y) -- (z);
\end{scope}
\end{tikzpicture}
The alignment is broken, so according to the manual I change the anchor to mid:
\begin{tikzpicture}
\begin{scope}[every node/.style={anchor=mid}]
\node (x) {x};
\node at ($(x)+(2,0)$) (y) {y};
\node at ($(x)+(4,0)$) (z) {z};
\path[draw,red] (x) -- (y) -- (z);
%\path[draw,cyan] (x.mid) -- (y.mid) -- (z.mid);
\end{scope}
\end{tikzpicture}
Oh oh, now the path is not straight anymore. At least the alignment is correct because the center of x is also its mid, but if we use base instead:
\begin{tikzpicture}
\begin{scope}[every node/.style={anchor=base}]
\node (x) {x};
\node at ($(x)+(2,0)$) (y) {y};
\node at ($(x)+(4,0)$) (z) {z};
\path[draw,red] (x) -- (y) -- (z);
%\path[draw,cyan] (x.base) -- (y.base) -- (z.base);
\end{scope}
\end{tikzpicture}
And now both the alignment and the path are broken.
To fix it, we would need to add the anchors also to each reference of the node in subsequent commands:
\begin{tikzpicture}
\begin{scope}[every node/.style={anchor=base}]
\node (x) {x};
\node at ($(x.base)+(2,0)$) (y) {y};
\node at ($(x.base)+(4,0)$) (z) {z};
\path[draw,red] (x.base) -- (y.base) -- (z.base);
%\path[draw,cyan] (x.base) -- (y.base) -- (z.base);
\end{scope}
\end{tikzpicture}
Hence, the question: do we really have to? Or can we tell the nodes to "remember" that their anchor is mid, or base, or whatever?
Basically, I would want a way to modify the 3rd snippet at only one place and get the 4th output.
(As a bonus, if this "remembered" anchor could behave like the default one and obey the inner and outer seps, it would be even greater. But this seems to be another question altogether.)
MWE:
\documentclass[11pt]{article}
\usepackage{tikz}
\usetikzlibrary{calc}
\begin{document}
\begin{tikzpicture}
\begin{scope}[every node/.style={anchor=center}]
\node (x) {x};
\node at ($(x)+(2,0)$) (y) {y};
\node at ($(x)+(4,0)$) (z) {z};
\path[draw,red] (x) -- (y) -- (z);
\end{scope}
\end{tikzpicture}
\begin{tikzpicture}
\begin{scope}[every node/.style={anchor=mid}]
\node (x) {x};
\node at ($(x)+(2,0)$) (y) {y};
\node at ($(x)+(4,0)$) (z) {z};
\path[draw,red] (x) -- (y) -- (z);
%\path[draw,cyan] (x.mid) -- (y.mid) -- (z.mid);
\end{scope}
\end{tikzpicture}
\begin{tikzpicture}
\begin{scope}[every node/.style={anchor=base}]
\node (x) {x};
\node at ($(x)+(2,0)$) (y) {y};
\node at ($(x)+(4,0)$) (z) {z};
\path[draw,red] (x) -- (y) -- (z);
%\path[draw,cyan] (x.base) -- (y.base) -- (z.base);
\end{scope}
\end{tikzpicture}
\begin{tikzpicture}
\begin{scope}[every node/.style={anchor=base}]
\node (x) {x};
\node at ($(x.base)+(2,0)$) (y) {y};
\node at ($(x.base)+(4,0)$) (z) {z};
\path[draw,red] (x.base) -- (y.base) -- (z.base);
%\path[draw,cyan] (x.base) -- (y.base) -- (z.base);
\end{scope}
\end{tikzpicture}
\end{document}






\nodetext height and depth with\tikzset{every node/.append style={text height=2ex,text depth=1ex}}if you play a bit with the dimensions you will see that 1st and 2nd output will be the same or 1st and 3rd. – BambOo May 22 '20 at 16:57westor120? – T. Verron May 22 '20 at 17:07minimum size/width/heightoptions, but that is just my opinion – BambOo May 22 '20 at 17:09baseandmidanchors are really convenient for avoiding having to deal with varying heights and depths. – T. Verron May 22 '20 at 17:29\documentclass[tikz,border=3mm]{standalone} \usetikzlibrary{calc} \begin{document} \begin{tikzpicture} \begin{scope}[nodes={anchor=base,text height=2ex,text depth=0.25ex}] \node (x) {x}; \node at ($(x.base)+(2,0)$) (y) {y}; \node at ($(x.base)+(4,0)$) (z) {z}; \path[draw,red] (x) -- (y) -- (z); \end{scope} \end{tikzpicture} \end{document}. Note the.basein\node at ($(x.base)+(2,0)$) (y) {y};. – May 22 '20 at 17:48.baseimplicit when defining the nodex. – T. Verron May 22 '20 at 17:52calcbutpositioningwithbase right=2cm of x.calcis not really intended for node positioning in the way you discuss here. – May 22 '20 at 17:55basein the positioning argument, it knows that it should position relative tox's base, so the information seems to be there. Or is it like "base right" means "position the base relative to that other's base"? Then it's back to square one... – T. Verron May 22 '20 at 18:23x, should this line attach to its base? This you can achieve, but is probably not what you want. – May 22 '20 at 18:40