[Tex/LaTex] Tikz Edge Label Positioning mid anchor

positioningtikz-pgf

I would like to place labels below edges such that the letters don't wobble. I can place them on the edge using the mid anchor, but when I use below some other anchor is used to calculate the distance.

\documentclass{minimal}
\usepackage{tikz}
\usetikzlibrary{positioning}
\begin{document}
\begin{tikzpicture}
\tikzstyle{vertex}=[circle, draw, inner sep=0.5ex]
\node [vertex] (0) {};
\foreach \n/\e in {1/a,2/b,3/c,4/d,5/e,6/f,7/g,8/h} {
  \pgfmathtruncatemacro{\left}{\n-1}
  \node [vertex] (\n) [right=of \left] {};
  \draw  (\left) -- node[anchor=mid] {\e} (\n); %on the edge, no wobble
  \draw (\left) -- node [below] {\e} (\n); % below the edge, wobble
};
\end{tikzpicture}
\end{document}

Best Answer

node[below] means node[anchor=north] and labels wobble because they have different height. If you want all labels aligned you can choose base anchor which will align all labels to their baseline.

\documentclass[tikz,border=2mm]{standalone}
%\usepackage{tikz}
\usetikzlibrary{positioning}
\begin{document}
\begin{tikzpicture}
\tikzstyle{vertex}=[circle, draw, inner sep=0.5ex]
\node [vertex] (0) {};
\foreach \n/\e in {1/a,2/b,3/c,4/d,5/e,6/f,7/g,8/h} {
  \pgfmathtruncatemacro{\left}{\n-1}
  \node [vertex] (\n) [right=of \left] {};
  \draw (\left) -- node [draw, below=5mm, anchor=base]  (\e) {\e} (\n); % below the edge, don't wobble
};
\draw[red] (a.base)--(h.base);

\begin{scope}[yshift=-1cm]
\node [vertex] (0) {};
\foreach \n/\e in {1/a,2/b,3/c,4/d,5/e,6/f,7/g,8/h} {
  \pgfmathtruncatemacro{\left}{\n-1}
  \node [vertex] (\n) [right=of \left] {};
  \draw (\left) -- node [draw, below]  (\e) {\e} (\n); % below the edge, wobble
};
\draw[red] (a.north)--(h.north);
\end{scope}
\end{tikzpicture}
\end{document}

enter image description here