Apparently, the tikz keys row n
/column n
don't work in tikz-cd
diagrams:
\documentclass{scrartcl}
\usepackage{tikz-cd, tikz}
\begin{document}
\[
\begin{tikzcd}[row 1/.style={nodes={font=\color{red}}}]
A \rar \dar & B \dar \\
C \rar & D
\end{tikzcd}
\]
\[
\begin{tikzpicture}
\matrix[matrix of math nodes, row 1/.style={nodes={font=\color{red}}}]{
A & B \\
C & D \\
};
\end{tikzpicture}
\]
\end{document}
I would have expected the first line of the first equation show up in red, like in the second. As you can see, this is not the case.
How can I achieve what I want, without applying the style to every node and every arrow?
Edit: The style for the nodes I can control with a tikzcdset
before the diagram. But how about the arrows?
Edit 2: If possible, I'd like to have all arrows within row 1 red. If that's not possible, I'd be fine with all arrows starting in or defined in row 1.
Best Answer
Nodes:
To change the style of a row use
nodes={row 1/.style=red}
The other TikZ matrix options work similarly:
Arrows: [Note—there was an error in the earlier code.]
The arrows are more difficult. The reason is that the
\arrow
command (or its shortcuts) does nothing to the diagram at the point it is called. Initially, there is an empty<paths>
string, and every time an\arrow
command is encountered,is appended to
<paths>
. So to change the arrow colors for arrows in a certain row (say, row<r>
), we have to get into the path of the arrows. The code is somewhat complicated, requiring some inserted code with\pgfextra
, and then comparing the y-coordinate of the current<source node>
with that of the<r>-1
entry (located at(\tikzcdmatrixname-<r>-1)
).This is all put into a
tikzcdset
with a style calledrowarrows
(withcolarrows
defines similarly):Then when you call
\begin{tikzcd}[rowarrows=1/red]
, the result isNote the syntax
rowarrows=<row number>/<color>
.Combining this with the node solution from above:
You can mix and match node colors and arrow colors:
Coloring arrows in a column is similar:
One shortcoming (at the moment) is that it is only possible to color the arrows in one row or in one column. Not both.
Here is the complete code: