# Tikz: Alignment of labels relative to a split rectangle

Is there a way for accurate placement of labels relative to the center of each of the parts of a split rectangle? The following example shows two errors:

• Alignment is with the left side of the sub-part
• The vertical alignment seems to be wrong.

The following is a a minimal working example:

 \documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{positioning,shapes.multipart}

\begin{document}
\begin{tikzpicture}[
date/.style= {
rectangle split,
rectangle split horizontal,
rectangle split parts=3,
draw
}]
\node[date] (today) {
\nodepart{one}   {\texttt{2014}}
\nodepart{two}   {\texttt{01}}
\nodepart{three} {\texttt{01}}
};
\node[below=2mm of today.one] {\texttt{y}};
\node[below=2mm of today.two] {\texttt{m}};
\node[below=2mm of today.three] {\texttt{d}};
\end{tikzpicture}
\end{document}


• The problem is caused by the different height of the text in the three nodes, an issue which has been discussed in many other questions (see this or this). A quick fix: add \strut to the contents of the nodes i.e. \node[...]{\texttt{\strut d\strut}} – Bordaigorl Jan 2 '14 at 11:04

To fix the horizontal alignment, place them relative to today.one south etc. To fix the vertical alignment set the anchor of the nodes to base, which is the baseline of the text.

 \documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{positioning,shapes.multipart}

\begin{document}
\begin{tikzpicture}[
date/.style= {
rectangle split,
rectangle split horizontal,
rectangle split parts=3,
draw
}]
\node[date] (today) {
\nodepart{one}   {\texttt{2014}}
\nodepart{two}   {\texttt{01}}
\nodepart{three} {\texttt{01}}
};
\node[below=3mm of today.one south,anchor=base] {\texttt{y}};
\node[below=3mm of today.two south,anchor=base] {\texttt{m}};
\node[below=3mm of today.three south,anchor=base] {\texttt{d}};
\end{tikzpicture}
\end{document}

• Many thanks for such a quick and accurate answer! – Yossi Gil Jan 2 '14 at 11:20