[Tex/LaTex] Tikz, rectangle split, first part aligned abnormally

horizontal alignmenttikz-pgf

Some little code two draw a rectangle with 4 parts, from library shapes.multiparts.

\tikzset{
    font=\sffamily,
    BLOCK/.style={
        draw,
        align=center,
        text height=0.4cm,
        draw=red!50,
        fill=red!20,
        rectangle split, 
        rectangle split horizontal,
        rectangle split parts=#1, 
    }
}
\begin{tikzpicture}
    \node (h1) {host\_entry};
    \node[BLOCK=4, below=0 of h1]{
        \nodepart{one}dpid \nodepart{two}port
        \nodepart{three}IP\nodepart{four}MAC};
\end{tikzpicture}

Every thing is OK except for the first column of the rectangle, the text just aligns weirdly.

weird first column

Has anyone else encountered the same issue? And how to solve it?

Thanks!

Best Answer

As documented in the manual, the rectangle split part align key could help here. By default it is set to center so all the boxes that contain the node part contents are aligned by their centers, but I expect base is what is required.

However, what does seem to be a bug, is that the alignment doesn't affect the first part.

\documentclass[border=0.125cm]{standalone}
\usepackage{tikz}
\usetikzlibrary{shapes.multipart,positioning}
\begin{document}
\tikzset{
    font=\sffamily,
    BLOCK/.style={
        draw,
        align=center,
        text height=0.4cm,
        draw=red!50,
        fill=red!20,
        rectangle split, 
        rectangle split horizontal,
        rectangle split parts=#1, 
    }
}

\begin{tikzpicture}
\foreach \align [count=\y] in {top, center, base, bottom}{
    \node at (0,-\y*2) (h1) {host\_entry};
    \node[BLOCK=4, below=0 of h1,
    label=left:\align,
    rectangle split part align=\align]{
        \nodepart{one}dpid \nodepart{two}port
        \nodepart{three}IP\nodepart{four}MAC};
}
\end{tikzpicture}

\end{document}

enter image description here