I want to build a matrix of several nodes of different types. In my example there is a matrix containing two "modules" and one "label".
For convenience I wanted to use matrix of nodes
with nodes={module}
since there are modules than labels.
Now, if I want to set the style of the label, I would usually use |[label]|
as in:
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{matrix}
\tikzset{
module/.style={draw, rectangle, fill=white, minimum width=4cm, minimum height=0.8cm},
label/.style={ }
}
\begin{document}
\begin{tikzpicture}
\matrix[fill=black!20, matrix of nodes, nodes={module}]
{
|[label]| Label \\ % this doesn't produce the desired output
Module 1 \\
Module 2 \\
};
\end{tikzpicture}
\end{document}
This produces:
Sure I could just specify every node explicitly, but this seems quite cumbersome. Is there a better solution?
Best Answer
As
label
is predefined style in TikZ, for my answer I'll usemymodule
andmylabel
in place ofmodule
andlabel
.What is happening here is that when you put
nodes={mymodule}
and then|[mylabel]|
, the style of the cell became equivalent to|[mymodule,mylabel]|
. So ifmylabel/.style={}
finaly the style of your cell is just like for all other cells|[mymodule]|
.As @user43963 says in his comment, you have to overwrite the properties that you don't want anymore. Like this: