如何访问节点标签的位置?

如何访问节点标签的位置?

这是我的代码的摘录:

\node (secondsong) [matrix,draw, rounded rectangle,label={song}]{
    \node (fstittel) {\_tittel};
    \node (fstittelvar) [right=of fstittel, rectangle, draw] {``Money''};
    \node (fsartist) [below=2pt of fstittel] {\_artist};
    \node (fsartistvar) [right=of fsartist, rectangle, draw] {``Pink Floyd''};\\
};

我现在想在节点标签周围画一个矩形,并在矩形secondsong框内画一个箭头。我该怎么做呢?

我尝试\path[draw, -latex'] (secondsong.label) -> (secondsong);绘制箭头,但是没有.label节点变量之类的东西。

这是否可以立即实现,还是我需要制作自己的自定义节点并将其放置在我的盒子上方?

当前屏幕 所需屏幕

答案1

欢迎!您可以为标签指定名称和样式。

\documentclass[tikz,border=3mm]{standalone}
\usetikzlibrary{arrows,positioning,shapes.misc}
\begin{document}
\begin{tikzpicture}
\node (secondsong) [matrix,draw, rounded rectangle,
label={[name=song, rounded rectangle,draw,yshift=1em]:song}]{
    \node (fstittel) {\_tittel}; 
    \node (fstittelvar) [right=of fstittel, rectangle, draw] {``Money''}; 
    \node (fsartist) [below=2pt of fstittel] {\_artist}; 
    \node (fsartistvar) [right=of fsartist, rectangle, draw] {``Pink Floyd''};\\
};
\path[draw, -latex'] (song) -- (secondsong);
\end{tikzpicture}
\end{document}

在此处输入图片描述

让我提一下,您还可以使用pin

\documentclass[tikz,border=3mm]{standalone}
\usetikzlibrary{arrows,positioning,shapes.misc}
\begin{document}
\begin{tikzpicture}[every pin edge/.style={latex'-}]
\node (secondsong) [matrix,draw, rounded rectangle,
pin={[rounded rectangle,draw]above:song}]{
    \node (fstittel) {\_tittel}; 
    \node (fstittelvar) [right=of fstittel, rectangle, draw] {``Money''}; 
    \node (fsartist) [below=2pt of fstittel] {\_artist}; 
    \node (fsartistvar) [right=of fsartist, rectangle, draw] {``Pink Floyd''};\\
};
\end{tikzpicture}
\end{document}

在此处输入图片描述

或者,如果你想要所有的引脚(比如说,在示波器中)都有一个圆角矩形边框,使用

\documentclass[tikz,border=3mm]{standalone}
\usetikzlibrary{arrows,positioning,shapes.misc}
\begin{document}
\begin{tikzpicture}[every pin edge/.style={latex'-},every pin/.style={rounded rectangle,draw}]
\node (secondsong) [matrix,draw, rounded rectangle,
pin={above:song}]{
    \node (fstittel) {\_tittel}; 
    \node (fstittelvar) [right=of fstittel, rectangle, draw] {``Money''}; 
    \node (fsartist) [below=2pt of fstittel] {\_artist}; 
    \node (fsartistvar) [right=of fsartist, rectangle, draw] {``Pink Floyd''};\\
};
\end{tikzpicture}
\end{document}

相关内容