5

Suppose I want to have a different format for the first column of a matrix of nodes compared to the rest of the nodes in the matrix. Using the column 1/.style=mycol I can assign a style to that column, but no matter how I assign the styles, certain key settings for the column can't be overridden if they are set in the row.

For example, if I set rounded corners or text depth in the row, how can I subsequently make the column have sharp corners other than setting it individually in each cell (as I did in row 2 in the example)?

I'm particularly interested in the text depth key, since setting text depth screws up the centring of text in the nodes, but I would like to have text depth set in the rows but not in the first column. Is there a way to unset it?

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{matrix}
\tikzset{
    myrow/.style={align=center,minimum size=2cm,fill=#1,text width=2cm,anchor=center,
    rounded corners,
%   text depth=2cm
    },
    mycol/.style={sharp corners, align=center, minimum size=2cm,text width=2cm,anchor=center},
    ,column sep=.25cm,row sep=.25cm}

\begin{document}
\begin{tikzpicture}[
    row 1/.style={nodes={myrow=red!80}},
    row 2/.style={nodes={myrow=blue!60}},
    column 1/.style={nodes={mycol}}]
\matrix[matrix of nodes]{
A title 
    & Some text 
    & More text
    & Even more\\
|[sharp corners]|Another title
    & Some text
    & More text
    & Even more\\
};
\end{tikzpicture}
\end{document}

enter image description here

1

1 Answer 1

6

Regarding the second question, how to undo/unset text depth=2cm: Use the option without argument:

..., text depth=, ...

Regarding the first question, how to execute the column style after the row style, observe that the Tikz manual explains in section 20.3.3. (Cell Styles and Options) that the following styles are executed in the given order: column〈number〉, every odd/even column, row〈number〉, every odd/even row, row〈row number〉column〈column number〉.

So the column options are overwritten by the row options. To obtain column options that are applied last, we have to add the code to the row options, using the fact that the counter \pgfmatrixcurrentcolumn contains the current column number. For the given sample code, this means:

\tikzset
   {myrow/.style={rounded corners, dominant column \the\pgfmatrixcurrentcolumn/.try},
    mycol/.style={sharp corners}
   }

\begin{tikzpicture}%
   [row 1/.style={nodes={myrow}},
    dominant column 1/.style={mycol}
   ]

Here is the complete sample code.

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{matrix}
\tikzset{
    myrow/.style={align=center,minimum size=2cm,fill=#1,text width=2cm,anchor=center,
    rounded corners,
    text depth=2cm,
    dominant column \the\pgfmatrixcurrentcolumn/.try
    },
    mycol/.style={sharp corners, text depth=},
    column sep=.25cm,row sep=.25cm}

\begin{document}
\begin{tikzpicture}[
    row 1/.style={nodes={myrow=red!80}},
    row 2/.style={nodes={myrow=blue!60}},
    dominant column 1/.style={mycol}]
\matrix[matrix of nodes]{
A title 
    & Some text 
    & More text
    & Even more\\
Another title
    & Some text
    & More text
    & Even more\\
};
\end{tikzpicture}
\end{document}

enter image description here

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .