3

I'd like to color individual columns in a 3x3 matrix created using \blockarray. I wish to give one color to the first column, and a second color to the 2nd and 3rd column. I found the answers two this question helpful, however, they do not seem to solve my problem.

However, I somehow cannot get the first answer using \columncolor from the xcolor package to work in this environment:

\documentclass{article}
\usepackage{amsmath}
\usepackage[table]{xcolor}
\usepackage{blkarray} % blockarrays; 

\begin{document}

\begin{align*}
\begin{blockarray}{ccc}
        \begin{block}{\BAmulticolumn{3}{>{}c}}
            \oint_{S^\textnormal{rec}}&\\
        \end{block}
        \begin{block}{(>{\scriptstyle}>{\columncolor{olive!20}}c>{\scriptstyle}c>{\scriptstyle}c)}
            a &\cdots & b\\
            \vdots&\ddots&\vdots\\
            cd &\cdots&N_\textnormal e\\
        \end{block}
\end{blockarray}
\end{align*}

\end{document}

It throws the following error message:

! Undefined control sequence.
\BA@.[10002,1]u ...\BA@bdollar \hfil \columncolor
{olive!20}\scriptstyle
l.19 \end{align*}

The second answer using the package hf-tikz and \tikzmark is also not solving the issue, as it fails for column entries of different lengths.

Can someone help me getting this to work in the \blockarray environment?

2

I don't know how to solve the problem with \blockarray, but I think you can reach your desired result with a TikZ matrix of math nodes.

\documentclass{article}
\usepackage{amsmath}
\usepackage[table]{xcolor}
\usepackage{blkarray} % blockarrays; 

\usepackage{tikz}
\usetikzlibrary{matrix, positioning}

\begin{document}
\begin{tikzpicture}
    \node (A) {$\oint_{S^\textnormal{rec}}$};
    \matrix[
        below=-2pt of A,
        inner xsep=0pt,
        matrix of math nodes,
        nodes={
            text width=1.2em, 
            text height=1.4ex,
            text depth=.5ex, 
            align=center, 
            font=\scriptsize, 
        },
        left delimiter={(},right delimiter={)},
        column 1/.style={nodes={fill={olive!20}}}
        ] {
        a &[6pt]\cdots &[6pt] b\\
        \vdots&\ddots&\vdots\\[-4pt]
        cd &\cdots&N_\textnormal e\\
        };
\end{tikzpicture}
\end{document}

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.