19

within \tikzset{...} I defined

row 1/.style={
    nodes={
        fill=black,
        text=white,
        %font=\bfseries
    }
}

such that for every table/matrix the first row is black with white text. When I now manually add

row 1/.style={nodes={text height=1em, text depth=3em}}

to a specific matrix the other options I used within the tikzset (fill=black, text=white) are gone, so I would have to write them again in that row 1/.style:

row 1/.style={nodes={text height=1em, text depth=3em, fill=black, text=white}}

Is it possible to just ADD the 2 options above to the already defined ones?

0

1 Answer 1

29

As mentioned in section 82.4.4 Defining Styles of the TikZ manual (for version 3.0.1a, dated 29 Aug 2015), you can use stylename/.append style={<options>} to append to the end of an existing style. (There is also .prefix style which prepends to the style.)

So for your specific case, use

row 1/.append style={nodes={text height=1em, text depth=3em}}

(That this works also relies on the fact that nodes is a shorthand for every node/.append style={}.)

Complete example:

\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{matrix}
\tikzset{row 1/.style={
    nodes={
        fill=black,
        text=white,
        %font=\bfseries
    }
}}

\begin{document}

\begin{tikzpicture}
\matrix [matrix of nodes] { a & b \\ c& d \\ e & f \\};
\end{tikzpicture}

\tikzset{row 1/.append style={nodes={text height=1em, text depth=3em}}}

\begin{tikzpicture}
\matrix [matrix of nodes] { a & b \\ c& d \\ e & f \\};
\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 .