如何命名标签节点?

如何命名标签节点?

tikzpicture我最近发现了通过键调整基线的可能性baseline=...。但是,这要求基线应定位的节点具有适当的名称。对于某些节点类型,例如使用键生成的节点label=...,如何命名并不明显。

在下面的例子中,如何才能使下面两张图片中的标签读数A与它们之间的箭头的基线对齐?

\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{positioning}
\begin{document}
\begin{tikzpicture}%[baseline=(Alabel.base)]
\coordinate[draw,shape=circle,label=left:Y](Y);
\coordinate[draw,shape=circle,right=of Y,label=right:A] (A);
\coordinate[draw,shape=circle,above=of Y,label=left:X] (X);
\coordinate[draw,shape=circle,below=of Y,label=left:Z] (Z);
\draw[->,shorten >=5pt,shorten <=5pt] (Y) -- (A);
\draw[->,shorten >=5pt,shorten <=5pt] (X) -- (A);
\draw[->,shorten >=5pt,shorten <=5pt] (Z) -- (A);
\end{tikzpicture}
$\Rightarrow$
\begin{tikzpicture}%[baseline=(Alabel.base)]
\coordinate[draw,shape=circle,label=left:Y](Y);
\coordinate[draw,shape=circle,right=of Y,label=right:A] (A);
\coordinate[draw,shape=circle,above=of Y,label=left:X] (X);
\draw[->,shorten >=5pt,shorten <=5pt] (Y) -- (A);
\draw[->,shorten >=5pt,shorten <=5pt] (X) -- (A);
\end{tikzpicture}
\end{document}

答案1

按照 PGFmanual,可以使用语法设置标签节点的属性

label={[key=value]position:text}

在给定的示例中,解决方案如下:

\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{positioning}
\begin{document}
\begin{tikzpicture}[baseline=(Alabel.base)]
\coordinate[draw,shape=circle,label=left:Y](Y);
\coordinate[draw,shape=circle,right=of Y,label={[name=Alabel]right:A}] (A);
\coordinate[draw,shape=circle,above=of Y,label=left:X] (X);
\coordinate[draw,shape=circle,below=of Y,label=left:Z] (Z);
\draw[->,shorten >=5pt,shorten <=5pt] (Y) -- (A);
\draw[->,shorten >=5pt,shorten <=5pt] (X) -- (A);
\draw[->,shorten >=5pt,shorten <=5pt] (Z) -- (A);
\end{tikzpicture}
$\Rightarrow$
\begin{tikzpicture}[baseline=(Alabel.base)]
\coordinate[draw,shape=circle,label=left:Y](Y);
\coordinate[draw,shape=circle,right=of Y,label={[name=Alabel]right:A}] (A);
\coordinate[draw,shape=circle,above=of Y,label=left:X] (X);
\draw[->,shorten >=5pt,shorten <=5pt] (Y) -- (A);
\draw[->,shorten >=5pt,shorten <=5pt] (X) -- (A);
\end{tikzpicture}
\end{document}

示例对齐

相关内容