我对 tikz
不太熟悉, 不确定是否有现成的方案来处理这个问题, 我自己造了个轮子
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{calc}
\begin{document}
\makeatletter
\def\pgfgetnodeheight(#1)#2{
\path ($(#1.south) - (#1.north)$);
\pgfmathsetmacro#2{veclen(\pgf@x, \pgf@y)}
\edef#2{#2pt}
}
\def\pgfgetnodewidth(#1)#2{
\path ($(#1.east) - (#1.west)$);
\pgfmathsetmacro#2{veclen(\pgf@x, \pgf@y)}
\edef#2{#2pt}
}
\makeatother
\begin{tikzpicture}
\node[anchor = south west, draw, align = left] (a) {text width \\ text width};
\pgfgetnodewidth(a)\nWidth
\pgfgetnodeheight(a)\nHeight
\draw[red] (0, -.1) -- (\nWidth, -.1) node[midway, below, text = black] {\nWidth};;
\draw[blue] (-.1, 0) -- (-.1, \nHeight) node[midway, left, text = black] {\nHeight};
\end{tikzpicture}
\end{document}