2

The chain seems to be properly aligned without the labels; adding labels seems to break it:

\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{chains}
\begin{document}
  \begin{tikzpicture}[start chain = going right, node distance=0, every node/.style={on chain,minimum width=10ex,draw}]
    \node [label=above:{a}] {1};
    \node [label=above:{b}] {2};
    \node [label=above:{c}] {3};
    \node [label=above:{d}] {4};
    \node {5};
    \node {6};
    \node {7};
    \node {8};
  \end{tikzpicture}
\end{document}

enter image description here

  • 1
    labels are also nodes so every node ... ;) – percusse Apr 2 '15 at 17:56
  • Indeed. What got me confused is that the labels did not have their border drawn. – Yossi Gil Apr 2 '15 at 18:06
2

As mentioned by @percusse, labels are nodes as well, so the every node style applies to these as well. To align just "plain" nodes, define a new style.

\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{chains}
\begin{document}
  \begin{tikzpicture}[start chain = going right, node distance=0, chain/.style={on chain,minimum width=10ex,draw}]
    \node [label=above:{a},chain] {1};
    \node [label=above:{b},chain] {2};
    \node [label=above:{c},chain] {3};
    \node [label=above:{d},chain] {4};
    \node [chain] {5};
    \node [chain] {6};
    \node [chain] {7};
    \node [chain] {8};
  \end{tikzpicture}
\end{document}

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.