我想“重复使用”一些节点的标签,如下例所示
\documentclass[a4paper,12pt,oneside,titlepage]{report}
\usepackage{tikz}
\usetikzlibrary{positioning}
\tikzset{
label node/.style = {
rectangle,
minimum size = 6mm,
rounded corners = 2mm,
very thick,
draw = black!50,
top color = white,
bottom color = black!20,
font = \sffamily,
anchor = east,
}
}
\begin{document}
\begin{tikzpicture}[line width = 1pt]
\node(A) [label node] at (-1, 0) {Node A};
\node(B) [label node] at (2, 0) {A.label};
\end{tikzpicture}
\end{document}
因此,我不想使用“A.label”作为节点 B 的标签,而是希望使用“节点 A”作为其标签,而无需明确写出它,即从节点 A“获取”标签文本。
答案1
据我所知,TikZ 没有提供这种可能性。节点内容未存储,也直接作为框处理。我只需使用一个保存内容并可重复使用的宏:
\documentclass[a4paper,12pt,oneside,titlepage]{report}
\usepackage{tikz}
\usetikzlibrary{positioning}
\tikzset{
label node/.style = {
rectangle,
minimum size = 6mm,
rounded corners = 2mm,
very thick,
draw = black!50,
top color = white,
bottom color = black!20,
font = \sffamily,
anchor = east,
}
}
\begin{document}
\begin{tikzpicture}[line width = 1pt]
\def\LabelA{Node A}
\node(A) [label node] at (-1, 0) {\LabelA};
\node(B) [label node] at (2, 0) {\LabelA};
\end{tikzpicture}
\end{document}