3

What is the default separation between a point and its label when using thecoordinate command? In the following code, I plot some dots on a grid using label option and "." to typeset the dot. The dot serves as the label in this code.

There is some displacement of the label from its point. I would like to know what this displacement is so that I can be consistent in the positioning of labels. The option

[label distance=<- (a measure with units)>]

within the label option will decrease this distance by <a measure with units>.

It seems that if the node is to be placed over the point, which can be specified by declaring the angle of 90 or not declaring any angle, [label distance=-4pt] seems to eliminate the artificial displacement. If the label is to be placed to the right of the point, [label distance=-5pt] seems to eliminate the artificial displacement.

Why would you need to compensate by different amounts for a node that is place to the right or above a node?! If the label is to be put above right of the point, the label distance option cannot eliminate the artificial displacement. Can this displacement be suppressed?

\documentclass{amsart}
\usepackage{tikz}
\usetikzlibrary{calc,angles,positioning,intersections}

\begin{document}
\begin{tikzpicture}
\draw [help lines] (-2,-2) grid (2,2);

\coordinate[label={[label distance=-4pt]90:$.$}] (A) at (1,1);
\coordinate[label={[label distance=-5pt]0:$.$}] (A) at (0,0);

\coordinate[label={[label distance=-5pt]45:$.$}] (A) at (-1,-1);
\coordinate[label={[label distance=-5.5pt]45:$.$}] (A) at (0,-1);
\coordinate[label={[label distance=-6pt]45:$.$}] (A) at (1,-1);

\end{tikzpicture}
\end{document}
user74973
  • 4,071
  • 1
    I believe the label is placed not relative to the center of the node but relative to its closest edge. – A.Ellett May 17 '15 at 00:10
  • 1
    The created label (just a node) is by default of the shape rectangle and so it might seem that the distance is different, depending on which anchor on the label will be used. (Also the inner and outer xseps and yseps will affect the placement.) Set every label/.append style={draw} to see what I mean. – Qrrbrbirlbel May 17 '15 at 00:11
  • @A.Ellett In this case, since the label is ., the node should be a square. So, the label distance=<some measure> should be the same whether the label is above or to the right of the point. – user74973 May 17 '15 at 00:17
  • @Qrrbrbirlbel How about using inner sep=0pt? Wouldn't that put the label, which is ., at the point? (I did try that, but I didn't include it in the code.) – user74973 May 17 '15 at 00:20
  • Yes, however, there is also outer sep (defaults to .5\pgflinewidth so that the border lies on the outside of a drawn shape). Note, that the $.$ has different dimensions in vertical and horizontal dimensions, see every label/.append style={draw, inner sep=0pt}. (However, I assume the actual label will contain actual text/math and not just the dot.) Try to set the label's shape to circle. – Qrrbrbirlbel May 17 '15 at 00:25
  • @Qrrbrbirlbel I did not know that a period was not a circular disc. Can I put the label in a textbox with no width and no length? – user74973 May 17 '15 at 00:34
  • @Qrrbrbirlbel I did put the . in a circular node, and I had inner sep=0pt and outer sep=0pt. The . cannot be placed at the origin ... without other options. – user74973 May 17 '15 at 00:36
  • Try the following \documentclass{standalone} \setlength\fboxsep{0pt} \begin{document} \fbox{$.$} \end{document} and you can see how the horizontal and vertical dimensions are different. – A.Ellett May 17 '15 at 00:37
  • @A.Ellett Give me two minutes. – user74973 May 17 '15 at 00:38
  • @A.Ellett I will add \setlength\fboxsep{0pt} to my current file. – user74973 May 17 '15 at 00:39
  • whoa! not what I was suggesting. I was just suggesting your create a standalone document in which you can see that $.$ has different horizontal and vertical widths. It's not a suggestion for how to solve your problem. @Qrrbrbirlbel's suggestions about changing the node shape to circle is what you should do. – A.Ellett May 17 '15 at 00:41
  • @A.Ellett Yeah, you're right. That was ugly. What is a standalone? – user74973 May 17 '15 at 00:42
  • @A.Ellett By the way, I already replied to Qrrbrbirlbel that putting the . in a circular node by itself won't work. – user74973 May 17 '15 at 00:43
  • @A.Ellett From the fbox, I see that the period is a circular disc but the node surrounding it is much wider than it is tall. – user74973 May 17 '15 at 00:47
  • If you compiled the standalone document, there's no node that you're working with. That's what $.$ looks like. LaTeX adds various space around this construct. If you just want a point, then you should do something more like \node[circle,fill,inner sep=0.2pt,outer sep=0pt] at (<node-name/coordinate>); – A.Ellett May 17 '15 at 00:50
  • @Qrrbrbirlbel I think that A.Ellett has given me a very nice explanation. – user74973 May 17 '15 at 23:39

1 Answers1

3

TikZ does a great job for the things is does. And, generally it does exactly what you would want it to do. But occasionally, you may want to do something---such as labeling nodes and coordinates---but TikZ's approach may not be what you have in mind.

If I understand what you have in mind here, you'll want create the labels for your coordinates yourself and not rely on what TikZ thinks you want to do.

In this following example, I create my own custom labels. I've created nodes and draw them in orange. I then create the label for the node at the precise distance I desire from the center of the node to be labeled. The label itself is in red. I draw a circle in light blue of radius equal to the distance desired from the center of the node. I've also left your nodes and their labels in there.

\documentclass{amsart}
\usepackage{tikz}
\usetikzlibrary{calc,angles,positioning,intersections}

\begin{document}
\begin{tikzpicture}
\draw [help lines] (-2,-2) grid (2,2);

\coordinate[label={[label distance=-4pt]90:$.$}]   (A1) at (1,1);
\coordinate[label={[label distance=-5pt]0:$.$}]    (A2) at (0,0);

\coordinate[label={[label distance=-5pt]45:$.$}]   (A3) at (-1,-1);
\coordinate[label={[label distance=-5.5pt]45:$.$}] (A4) at (0,-1);
\coordinate[label={[label distance=-6pt]45:$.$}]   (A5) at (1,-1);

\coordinate (A) at (1,1);
\coordinate (B) at (0,0);
\coordinate (C) at (-1,-1);
\coordinate (D) at (0,-1);
\coordinate (E) at (1,-1);

\foreach \myn/\mya/\myd in {A/90/4pt,
                            B/0/5pt,
                            C/45/5pt,
                            D/45/5.5pt,
                            E/45/6pt}
  {
    \node[circle,inner sep=1pt,draw,orange] at (\myn) {};
    \draw[blue!20]  (\myn) circle (\myd);
    \node[text=red] (\myn/label) at ($(\myn)+(\mya:-\myd)$) {$.$};
  }

\end{tikzpicture}
\end{document}

enter image description here

Basically what I'm doing in the \foreach loop is: to take some node (or coordinate) A that's already been defined. Then to create my own label which is precisely placed, I would use the following syntax (provided you are using the calc library)

\node[<options>] (A/label) at ($(A)+(<angle>:<distance>)$) {<label content>};

If you're not using the calc library, then you can define the label via

\path (A) ++ (<angle>:<distance>) node[<node options>] (A/label) {<label content>};

There's nothing special about the label name. You could name it anything you want, but it's probably best, in terms of readability of your code, to name it for what it is.

A.Ellett
  • 50,533
  • Yes, you do understand that I wanted to determine the placement of labels with respect to their coordinates - and to be exact about it. I see from the concentric circles and from the red dots in your display that your code can be readily adapted to place labels at precise distances from a point. – user74973 May 17 '15 at 16:54
  • I am not familiar with \foreach commands; so, I would not be able to readily adapt your code. May you take the time to give me the same display without using the \foreach commands ... or explain to me the syntax? – user74973 May 17 '15 at 16:54
  • @user74973 I've explained how I'm creating the labels. Hopefully that makes it clear how to do this on your own. – A.Ellett May 17 '15 at 19:59
  • Thanks. I will look at your explanation and the manual. (Yes, I do use the calc package.) – user74973 May 17 '15 at 23:15
  • Without using the \foreach command, though, I would like to understand the manual way to precisely place the labels. I think that I need clarification on one part of the command that you give using the calc package. I think that you are using it when specifying the location of the point, which you call label/A, with ($(A)+(<angle>:<distance>)$). I suppose that (A) is referring to the point (1,1). – user74973 May 17 '15 at 23:36
  • So, the location of the node, which in this case is an orange dot, is going to be the vector sum of (1,1) and the point, expressed in polar coordinates, as (<angle>:<distance>). Is that correct? – user74973 May 17 '15 at 23:36
  • Is that correct? – user74973 May 20 '15 at 13:06
  • @user74973 I'm confused by what you're saying. There is a node defined, as say A, which I've drawn in orange. Then, I defined a new node relative to A which I place using polar coordinates. This new node I call A/label. If you choose to think about this as vectors, then A is simply hardwired at a particular coordinate. It's label, A/label, is the vector sum of the coordinate for A and (<angle>:<distance>). – A.Ellett May 20 '15 at 13:16
  • You have a node at a point called A. You want to place a new node with respect to A, and you do this by vector addition: (A)+(<angle>:<distance>). The label for this new point is A/label. Is that correct? – user74973 May 21 '15 at 15:17
  • @user74973 Isn't that what I just explained? I'm a bit lost about what I'm not communicating clearly to you. – A.Ellett May 21 '15 at 16:29
  • Apparently, you are clearly communicating to me. I just was paraphrasing what you had told me. – user74973 May 21 '15 at 16:32