Tikz:標籤相對於分割矩形的對齊方式

Tikz:標籤相對於分割矩形的對齊方式

有沒有辦法相對於分割矩形的每個部分的中心準確放置標籤?以下範例顯示了兩個錯誤:

  • 與子零件的左側對齊
  • 垂直對齊似乎是錯誤的。

以下是一個最小的工作範例:

 \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}

呈現上述文件時

答案1

要固定水平對齊,請將它們相對於等today.one south放置。base

在此輸入影像描述

 \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}

相關內容