可以为各个节点部分元素分配颜色。
\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{shapes,patterns}
\begin{document}
\begin{tikzpicture}[stack/.style={
rectangle split,
rectangle split parts=4,
rectangle split part fill={red!40,blue!40,green!40,yellow!40},
draw}]
\node [stack] (mystack) {
\nodepart{one}\small{Foo}
\nodepart{two}\small{Bar}
\nodepart{three}\small{Baz}
\nodepart{four}\small{Qux}
};
\end{tikzpicture}
\end{document}
是否可以以类似的方式分配模式?我rectangle split part pattern
已经尝试过了,但不起作用。
答案1
这是一个免费的解决方法,可能会摧毁一切
\documentclass[tikz]{standalone}
\usepackage{tikz}
\usetikzlibrary{shapes,patterns}
\begin{document}
\makeatletter
\begin{tikzpicture}[stack/.style={
scale=3,
rectangle split,
rectangle split parts=4,
/utils/exec={
\def\pgfsetfillcolor##1{
\message{^^J^^J The "color" is \string##1= ##1 ^^J^^J}
\expandafter\expandafter\expandafter\pgfsetfillpattern##1
}
},
rectangle split part fill={
{fivepointed stars}{red},
{fivepointed stars}{blue},
{fivepointed stars}{green},
{fivepointed stars}{yellow}
},
draw}]
\node [stack] (mystack) {
\nodepart{one}\small{Foo}
\nodepart{two}\small{Bar}
\nodepart{three}\small{Baz}
\nodepart{four}\small{Qux}
};
\end{tikzpicture}
\end{document}