Edge nodes, auto and node distance

Consider the following MWE

\documentclass{article}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\draw (0,0)--(1,1) node[auto,midway] {$A$}
-- (2,0) node[auto,midway] {$B$};
\end{tikzpicture}
\end{document}


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.

-

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:
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
@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