[Tex/LaTex] TikZ rectangle split with changing alignment

horizontal alignmenttikz-pgf

I try to draw tikz nodes with rectangle split. I want the first part to be centered and the second part aligned left. This is what I have tried:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{positioning,shapes}

\begin{document}
  \tikzstyle{box}=[rectangle, draw=black, text width=3cm,
                   rectangle split, rectangle split parts=2]
  \begin{tikzpicture}
    \node (A) [box] {
      First
      \nodepart{second}Second
    };
    \node (B) [below=of A, box] {
      \begin{center}First\end{center}
      \nodepart{second}Second
    };
    \node (C) [below=of B, box, align=center] {
      First
      \nodepart{second}\flushleft Second
    };
  \end{tikzpicture}
\end{document}

A has the correct size, but everything is left-aligned.

B has correct alignment, but the first part is larger than it needs to be.

C also has correct alignment, but the second part is largen than it needs to be.

How to do this properly?

Best Answer

You can use the optional argument of nodepart.

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{shapes}
\begin{document}
  \tikzstyle{box}=[rectangle, draw=black, text width=3cm,
                   rectangle split, rectangle split parts=2]
  \begin{tikzpicture}
    \node[align=center] (A) [box] {
      First
      \nodepart[align=left]{second}Second
    };
  \end{tikzpicture}
\end{document}

results in

enter image description here