我想设置所有节点的标签。我可以为每个节点(标签)分别执行此操作:
\begin{tikzpicture}[every label/.style={red}]
\node[draw, label=right:A label] (anode) {A node};
\node[draw, right=2cm of anode, label=right:Another label] {Another node};
\end{tikzpicture}
但这非常繁琐。如何将所有标签设置为位于节点右侧,就像所有节点的颜色一样?
答案1
我建议设置一个全局风格,例如rlabel
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{positioning}
\tikzset{
rlabel/.style = {label={right:#1}},
every label/.style={red},
}
\begin{document}
\begin{tikzpicture}
\node[draw, rlabel=A label] (anode) {A node};
\node[draw, right=2cm of anode, rlabel=Another label] {Another node};
\end{tikzpicture}
\end{document}