TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Consider the following MWE

 \draw (0,0)--(1,1) node[auto,midway] {$A$}
 -- (2,0) node[auto,midway] {$B$};

I am using auto here to get automatic left/right positioning. However, I am not satisfied with the distance between the edge labels and the edge itself, which is a bit too large (my real example is a picture with much more nodes in it, so there is room for confusion if they are not very close).

Is there a way to alter this distance? I tried adding node distance=something almost everywhere, but it seems to be ignored.

share|improve this question
up vote 18 down vote accepted

There's no gap between the nodes and the lines (node distance applies to a different positioning mechanism). You can see this if you activate draw for the nodes

There are two things you can do to move the text closer to the line: Either you decrease the inner sep, for example using inner sep=1pt, or you set the outer sep to a negative value, for example using outer sep=-3pt:

share|improve this answer
Thanks, this works! – Federico Poloni Dec 10 '12 at 16:34
As a minor tweak, you can consider adding the circle option to the nodes as well, so that the spacing won't depend on the direction of the edge. – T. Verron Dec 10 '12 at 16:38
@T.Verron: That's what I thought until very recently as well, but it turns out that the auto placement only uses the north, north west, west, etc. anchors to place the nodes. Try putting a circle node on a line from (0,0) to (1,3): The circle will intersect the line. I posted a code snippet at TikZ parallel Edges between Nodes that makes TikZ use degree-accuracy for placing the nodes. Also, ellipse nodes are better for ensuring consistent distance in case your text isn't square. – Jake Dec 10 '12 at 16:54
@Jake : Interesting, I didn't know that (and it happened to be invisible on this question's MWE). However, I find that if you have to use only one shape and inner sep for all directions, a circle still gives a better output than a rectangle (most notably on vertical edges). Personal taste of course. – T. Verron Dec 10 '12 at 17:23
@T.Verron: I was thinking of the case of a horizontal edge with a long label, say, \tikz \draw (0,0) -- node [auto] {A long label} (4,0);. If you use a circle there, the label will be moved really far from the edge, while using ellipse would keep it close to the edge. – Jake Dec 10 '12 at 17:45

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.