我有以下 TikZ 代码片段,它在矩阵中呈现一些选定的节点:
\tikzset{
red/.style={ nodes={font=\large} },
blue/.style={ nodes={font=\small} },
special red/.style={ text=red },
special blue/.style={ text=blue },
}
\matrix[red] {
\node {normal node 1}; &
\node [special red] {special red node}; &
\node {normal node 2}; \\
};
\tikzset{yshift=-1cm}
\matrix[blue] {
\node {normal node 1}; &
\node {normal node 2}; &
\node [special blue] {special blue node} ;\\
};
但我想通过仅使用special
节点中的样式并委托矩阵类型来呈现这些特殊节点来实现相同的结果。例如:
\tikzset{
...
}
\matrix[red] {
\node {normal node 1}; &
\node [special] {special red node}; &
\node {normal node 2}; \\
};
\tikzset{yshift=-1cm}
\matrix[blue] {
\node {normal node 1}; &
\node {normal node 2}; &
\node [special] {special blue node} ;\\
};
谢谢!
答案1
看来这个.is choice
钥匙能起到作用:
\tikzset{
red/.style={
nodes={
special/.default=red,
font=\large
}
},
blue/.style={
nodes={
special/.default=blue,
font=\small
}
},
special/.is choice,
special/red/.style={ text=green },
special/blue/.style={ text=blue },
}
\matrix[red] {
\node {normal node 1}; &
\node [special] {special red node}; &
\node {normal node 2}; \\
};
\tikzset{yshift=-1cm}
\matrix[blue] {
\node {normal node 1}; &
\node {normal node 2}; &
\node [special] {special blue node} ;\\
};