Hi i'm interested in how to add background to specific cells of a matrix.
I already know a bit about how to build a matrix, my given code looks like:
\usepackage{tikz}
\usetikzlibrary{arrows, fit, matrix, positioning, shapes}
\begin{tikzpicture}[>=latex]
\node (B) {$B^\prime=$};
\matrix (M) [matrix of math nodes,left delimiter={[}, right delimiter={]},
matrix anchor=west, right=0.5em of B,
column 1/.style={anchor=base east},
column 2/.style={anchor=base east},
column 3/.style={anchor=base east}]
{
a & b & c\\
b & d & e\\
c & e & a+b+1\\
};
\node [fit=(M-1-1) (M-1-3), draw, rectangle, blue]{};
\node [fit=(M-2-2) (M-2-3), draw, rectangle, blue]{};
\node [fit=(M-3-3) (M-3-3), draw, rectangle, blue]{};
\end{tikzpicture}
As you can see im creating a right-aligned matrix, because my element at cell(3,3) is very long. To point out that my matrix is quadratic, I thought about highlighting row elements 1-1 to 1-3, 2-2 to 2-3, and element 3-3.
I would want to give them a background color, lets say some sort of blue. I didn't manage to fill out the rectangles without covering the matrix elements below.
I would be greatful for any hints or solutions :)
|[fill=blue!30]|a & b & c\\
. If you want to fill the rectangles you draw with fit, you may want to load thebackgrounds
library and do the fills/fits in a scope\begin{scope}[on background layer]
such that the texts stay in the foreground. You can of course fill a whole column bycolumn 1/.style={anchor=base east,fill=red},
, say, and likewise for rows. – user121799 Sep 18 '18 at 12:40nodes={minimum height=6mm},
to the options of the matrix. Of course,6mm
is not carved in stone. – user121799 Sep 18 '18 at 13:02