TIKZ:获取当前节点的高度

TIKZ:获取当前节点的高度

我正在创建以下节点:

\node [style=Rectangle, label={[yshift=0.2cm]left:\tiny(1)}] (1) at
  (-5, 3) {Nuclear Production\\ Into Fuel Salt};

看看它说的是什么

yshift=0.2cm

我想要做的是获取当前节点的高度并将其除以 2,这样标签位置始终与节点的顶部和左侧对齐。

答案1

欢迎使用 TeX-SE!定义自己的标签样式可能比测量高度更容易。

\documentclass[tikz,border=3.14mm]{standalone}
\begin{document}
\begin{tikzpicture}[Rectangle/.style={rectangle,draw,align=center},
plabel/.style={append after command={node[anchor=south east,font=\tiny,inner
sep=0pt,outer sep=0pt] at (\tikzlastnode.north west){#1}}}]
\node [style=Rectangle, plabel={(1)}] (1) at
  (-5, 3) {Nuclear Production\\ Into Fuel Salt};
\end{tikzpicture}
\end{document}

在此处输入图片描述

答案2

让我将我的评论转化为答案:

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

\begin{document}
\begin{tikzpicture}
  \node[draw, align=center,
        label={[anchor=south east,font=\tiny, inner sep=0pt]north west:(1)}
        ]
        {Nuclear Production\\ Into Fuel Salt};
\end{tikzpicture}

% or shorter, by defining a node style "box"

\begin{tikzpicture}[
box/.style = {draw, align=center,
              label={[anchor=south east,font=\tiny, inner sep=0pt]north west:#1}
              }
                    ]
  \node[box=(1)] {Nuclear Production\\ Into Fuel Salt};
\end{tikzpicture}
\end{document}

两个例子都得出相同的结果:

在此处输入图片描述

相关内容