Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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}
share|improve this question
    
Please make sure that your example compiles -- the positioning library and \end{tikzpicture} was missing. –  Torbjørn T. Aug 6 '13 at 9:19
1  
Don't use numbers as node names. It will cause trouble if you refer to the angle anchors such as 4.90 –  percusse Aug 6 '13 at 9:47
    
I'd suggest using standalone instead of minimal. You can find some problems using minimal because, sometimes, it's too minimal. Look at What is the advantage of using minimal over article when creating a standalone graphic? –  Ignasi Aug 6 '13 at 9:47

1 Answer 1

up vote 3 down vote accepted

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

share|improve this answer

Your Answer

 
discard

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.