I'm working on a package and I want to draw constructions similar to the following:
This features 2 nodes. The small, circular node is located at some anchor on the border of the rectangular node, adjusted so that its centre aligns with the middle of the total height or width (as applicable) of the line outlining the rectangular one. In this particular case, the circular node is placed at the north anchor of the rectangular one, adjusted as described.
If I do the obvious thing and place the circular node at the rectangular node's appropriate anchor,
\node (x) [text node] at (0,1) {Hello World};
\node [circ node] at (x.north) {};
I get
which is not what I want.
I could force outer sep=0pt for the rectangular node, as suggested by Andrew Swann. However, I also need to draw connections between nodes and I want people to be able to draw additional connections in standard ways. Hence, this isn't really an option.
I can obtain the result I want by using instead
\node (t) [text node] {Hello World};
\pgflinewidthsaved=\pgflinewidth
\pgflinewidth=0pt
\node (p) [text node, phantom] at (t.center) {\phantom{Hello World}};
\node (c) [circ node] at (p.north) {};
\pgflinewidth=\pgflinewidthsaved
where the phantom style is defined as follows
phantom/.style={line width=0pt, fill=none, draw=none, anchor=center},
In order to ensure a match, I have to apply the main node's style to the phantom one and then override relevant settings in the phantom one. However, this is very fragile and a bit tricky. I need, for example, to eliminate any xshift, yshift, shift etc. in order for it to stand a chance and this can't be done by just setting these to zero, since such things are cumulative.
Is there a better way to achieve this kind of construct? Is it possible, for example, to create a modified version of the rectangle shape which would have additional anchors which take account of the line width? I looked at the code for rectangle but I don't know how this gets compiled with the line width or where this adjustment takes place. (I think the shape is stored more-or-less statically except for deferred, border anchors etc., so that this would not be possible, but I'm not certain.) Or is it possible to do this in any other relatively sane and more streamlined way?
Note that the code I'm giving here is greatly simplified. In the real case, I do not know at which of the rectangular node's anchors the circular one should be placed. Nor do I know the width of the line outlining the rectangular node or whether any line outlines it at all. That is, line width could have any value for the rectangular node, including 0pt. So I can't just shift the circular node a bit as I don't know by how much or in which direction to shift it. Nor do I know the size of the rectangular node or whether it is placed relative to something else. (I do know it is placed with the \node ... at (...) ... syntax.) I do not know whether any transformations have been applied to the node, such as xshift, rotate or whatever.
However, I'm prepared to prohibit use of rotate, if necessary, and I'm certainly not expecting this to work with anything strange, such as a canvas transformation or a switch of coordinate system. But I do need it to work with things like xshift. Right now, I'm just trying to drop these, but I'm not sure I have a good strategy for doing that. (That is, I have a strategy, but it assumes people will read the documentation, which I'd rather it didn't.)
MWE
\documentclass[border=10pt]{standalone}
\usepackage{tikz}
\newdimen\pgflinewidthsaved
\begin{document}
\begin{tikzpicture}
[
opacity=.5,
text node/.style={draw, line width=2pt, anchor=north},
phantom/.style={line width=0pt, fill=none, draw=none, anchor=center},
circ node/.style={fill, anchor=center, circle, minimum size=4pt, inner sep=0pt},
]
\node (t) [text node] {Hello World};
\pgflinewidthsaved=\pgflinewidth
\pgflinewidth=0pt
\node (p) [text node, phantom] at (t.center) {\phantom{Hello World}};
\node (c) [circ node] at (p.north) {};
\pgflinewidth=\pgflinewidthsaved
\node (x) [text node] at (0,1) {Hello World};
\node [circ node] at (x.north) {};
\node [font=\itshape, anchor=mid west] at (x.mid east) {default --- not wanted};
\node [font=\itshape, anchor=mid west] at (t.mid east) {wanted --- not default};
\end{tikzpicture}
\end{document}



outer sep=0ptintext nodestyle, then default position of circle is as you like to have. – Zarko Aug 11 '17 at 00:20outer sep? – cfr Aug 11 '17 at 15:12