节点中的文本对齐

节点中的文本对齐

为什么 360 没有与 Angle 垂直对齐?

我改变了text width,但情况并没有好转......

在此处输入图片描述

\documentclass[tikz,margin=3pt]{standalone}

\pgfkeys{/tikz/.cd,
    BLS/.store in=\BLS,
    BLS=1.1*\baselineskip
    }

    \tikzset{%
        TDPnode/.style={outer sep=0pt,inner sep=1pt,
                        minimum height=\BLS,draw,text depth=1.5pt},
        TDPetq/.style={TDPnode,anchor=north east,
            minimum width=3em + 10pt,fill=gray!40},
        TDPcas/.style={TDPnode,anchor=west,minimum width=3em},
        TDPfle/.style={>=stealth,semithick}
    }

\begin{document}
\begin{tikzpicture}
    \node[TDPetq] (B0) at (0,0) {Angle ()} ;
    \node[TDPcas,anchor=west] (B1) at (B0.east) {360} ;

\end{tikzpicture}
\end{document}

答案1

如果希望所有节点都按基线对齐,则所有节点都需要具有相同的text depthtext height

\documentclass[tikz,margin=3pt]{standalone}

\pgfkeys{/tikz/.cd,
    BLS/.store in=\BLS,
    BLS=1.1*\baselineskip
    }

    \tikzset{%
        TDPnode/.style={outer sep=0pt,inner sep=1pt,
                        minimum height=\BLS,draw, text depth=2pt, text height=8pt},
        TDPetq/.style={TDPnode,anchor=north east,
            minimum width=3em + 10pt,fill=gray!40},
        TDPcas/.style={TDPnode,anchor=west,minimum width=3em},
        TDPfle/.style={>=stealth,semithick}
    }

\begin{document}
\begin{tikzpicture}
    \node[TDPetq] (B0) at (0,0) {Angle ()} ;
    \node[TDPcas,anchor=west] (B1) at (B0.east) {360} ;

    \draw[red] (B0.base)--(B1.base);
    \draw[blue] (B0.base-|B0.west)--(B0.base-|B1.east);
\end{tikzpicture}
\end{document}

在此处输入图片描述

相关内容