我需要节点旁边的标签更小且颜色为绿色。我无法修改它。
\documentclass[tikz,border=3.14mm]{standalone}
\usetikzlibrary{shapes.multipart}
\tikzset{block/.style={
font=\sffamily,
draw=black,
thin,
fill=white!50,
rectangle split,
rectangle split horizontal,
rectangle split parts=#1,
outer sep=0pt},
}
\begin{document}
\def\lvld{1.2} % Choose level distance
\pgfmathsetmacro\shft{-6*\lvld} % Calculate the yshift for the green tree
\begin{tikzpicture}[level distance=\lvld cm,
level 1/.style={sibling distance=4cm},
level 2/.style={sibling distance=3cm},
level 3/.style={sibling distance=2cm},
level 3/.style={sibling distance=1.3cm},
edgedown/.style={edge from parent/.style={draw=black,thick,-latex}}%,
%edgeup/.style={edge from parent/.style={draw=green!50!black,thick,latex-}}
]
\node[block=1][label=right:{(0,0)}] (A) {(16,3)}
[grow=down,edgedown]
child {node[block=1][label=right:{(0,0)}] (B1) {(12,44)}
child {node[block=1][label=right:{(0,0)}] (C1) {(18,5)}
child {node[block=1][label=left:{(0,0)}] (D1) {(24,3)}
child {node[block=1][label=right:{(0,0)}] (E1) {(10,7)}}}
child {node[block=1][label=right:{(0,0)}] (D2) {(3,20)}}
}
}
\end{tikzpicture}
\end{document}
答案1
您可以将every label
样式更改为您想要的标签外观:
\documentclass[tikz,border=3.14mm]{standalone}
\usetikzlibrary{shapes.multipart}
\tikzset{block/.style={
font=\sffamily,
draw=black,
thin,
fill=white!50,
rectangle split,
rectangle split horizontal,
rectangle split parts=#1,
outer sep=0pt},
}
\begin{document}
\def\lvld{1.2} % Choose level distance
\pgfmathsetmacro\shft{-6*\lvld} % Calculate the yshift for the green tree
\begin{tikzpicture}[level distance=\lvld cm,
level 1/.style={sibling distance=4cm},
level 2/.style={sibling distance=3cm},
level 3/.style={sibling distance=2cm},
level 3/.style={sibling distance=1.3cm},
edgedown/.style={edge from parent/.style={draw=black,thick,-latex}},
every label/.style={green,font=\tiny}
%edgeup/.style={edge from parent/.style={draw=green!50!black,thick,latex-}}
]
\node[block=1][label=right:{(0,0)}] (A) {(16,3)}
[grow=down,edgedown]
child {node[block=1][label=right:{(0,0)}] (B1) {(12,44)}
child {node[block=1][label=right:{(0,0)}] (C1) {(18,5)}
child {node[block=1][label=left:{(0,0)}] (D1) {(24,3)}
child {node[block=1][label=right:{(0,0)}] (E1) {(10,7)}}}
child {node[block=1][label={right:{(0,0)}}] (D2) {(3,20)}}
}
};
\end{tikzpicture}
\end{document}