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}

相关内容