[Tex/LaTex] Edge nodes, auto and node distance

nodespositioningtikz-pgf

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.

Best Answer

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: