# How to force all labels to stay on the same horizontal line in Tikz

I'm trying to keep all of the labels at the same distance from the line. I've tried separating the nodes, but even if I remove all of the nodes except '1' and 'N+1', the three character label is higher. I've also tried:

• x-scale
• label distance
• label size = \tiny
• inner sep = 0pt
• outer sep = 0pt

But nothing seems to allow the three character labels to assume the same relative position to the line. Any advice? I've attached a quick-copy complete code as well as a picture.

\documentclass[12pt, twoside]{article}

\usepackage{tikz}
\tikzset{every node/.style={draw,shape=circle}}

\begin{document}

\begin{figure}
\centering
\begin{tikzpicture}
\tikzstyle{every node}=[draw,shape=circle]
\draw[very thick](0,0) node[circle,fill,inner sep=1pt,label=above:$1$](1){} -- (1,0);
\draw[very thick](1,0) node[circle,fill,inner sep=1pt,label=above:$2$](2){} -- (2,0);
\draw[very thick](2,0) -- (4,0);
\draw[very thick](4,0) node[circle,fill,inner sep=1pt,label=above:$i-1$](i-1){} -- (5,0);
\draw[very thick](5,0) node[circle,fill,inner sep=1pt,label=above:$i$](i){} -- (6,0);
\draw[very thick](6,0) node[circle,fill,inner sep=1pt,label=above:$i+1$](i+1){} -- (7,0);
\draw[very thick](7,0) -- (9,0);
\draw[dotted, very thick](9,0) node[circle,fill,inner sep=1pt,label=above:$N$](N){} -- (10,0)
node[circle,fill,inner sep=1pt,label=above:$N+1$](N+1){};
\end{tikzpicture}
\caption{Visualization of meshing elements and intervals including the complex $N+1$ node}
\label{fig:nodeline}
\end{figure}

\end{document}


Style every node define node style for labels too. When the label is wider, than the circle in your case is bigger and consequently the label virtually appear higher from line.

Edit: As Ignasi pointed in his comment below, also is necessary consider different text depth of labels. This are compensated below examples with:

every node/.append style = {text depth=0.2ex}


See, if the following solutions gives what you looking for:

\documentclass[12pt, twoside]{article}
\usepackage{tikz}

\begin{document}
\begin{figure}
\centering
\begin{tikzpicture}[
dot/.style = {circle,fill=black,inner sep=1pt, node contents={}}
every node/.append style = {text depth=0.2ex}
]
\draw[very thick] (0,0) node (1)   [dot,label=$1$]  -- (1,0);
\draw[very thick] (1,0) node (2)   [dot,label=$2$]  -- (2,0);
\draw[very thick] (2,0) -- (4,0);
\draw[very thick] (4,0) node (i-1) [dot,label=$i-1$] -- (5,0);
\draw[very thick] (5,0) node (i)   [dot,label=$i$]   -- (6,0);
\draw[very thick] (6,0) node (i+1) [dot,label=$i+1$] -- (7,0);
\draw[very thick] (7,0) -- (9,0);
\draw[dotted,very thick] (9,0)  node (N)   [dot,label=$N$] --
(10,0) node (N+1) [dot,label=$N+1$];
\end{tikzpicture}
\caption{Visualization of meshing elements and intervals including the complex $N+1$ node}
\label{fig:nodeline}
\end{figure}
\end{document}


Above code can be further simplified, for example with use of loop:

\documentclass[12pt, twoside]{article}
\usepackage{tikz}

\begin{document}

\begin{figure}
\centering
\begin{tikzpicture}[
dot/.style = {circle,fill=black,inner sep=1pt}
every node/.append style = {text depth=0.2ex}
]
\draw[very thick]           (0,0) -- (9,0);
\draw[dotted,very thick]    (9,0) -- (10,0);
\foreach \i/\j in {0/1, 1/2, 4/i-1, 5/i, 6/i+1, 9/N, 10/N+1}
\node (\j) [dot,label=$\j$] at (\i,0) {};
\end{tikzpicture}
\caption{Visualization of meshing elements and intervals including the complex $N+1$ node}
\label{fig:nodeline}
\end{figure}

\end{document}


In both cases the result is the same.

• I think that the lowest point of your labels is at same distance from the dot, but the final effect is that they are not vertically aligned because their text depth is not equal. – Ignasi Feb 6 '17 at 19:53
• @Ignasi, thank you for pointed me to this. I will correct this (unexpected) behavior of label text ... – Zarko Feb 6 '17 at 20:07