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}
17
  • 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 0: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 0: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 0: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 0: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 0:25
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.

11
  • 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

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.