6

I would like to highlight a row, a column and a specific cell in a matrix. I ended up using \cellcolor. My problem is that \cellcolor is taking too much space, therefore the matrix borders are being covered by the color. As you see in the below picture how the matrix is ruined by the color

enter image description here

and this is my code

\documentclass[12pt]{article}
\usepackage{amsmath}
\usepackage[table]{xcolor}


\begin{document}

\begin{align*}
\begin{bmatrix}
\cellcolor{green} ss &  \cellcolor{red!80} ss \\
\cellcolor{green} ss &  \cellcolor{red!80} ss \\
\end{bmatrix}
\end{align*}

\end{document}
8

In this case you may be better off using a traditional array construction:

enter image description here

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

\begin{document}

\[
  \left[\,\begin{array}{cc}
    \cellcolor{green} ss &  \cellcolor{red!80} ss \\
    \cellcolor{green} ss &  \cellcolor{red!80} ss \\
  \end{array}\,\right]
\]

\end{document}
10

If all the cells belonging to the same columns have the same color, with array you can specify the color of the column directly, without resorting to \cellcolor for each cell.

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

\begin{document}

\[
  \left[\,
  \begin{array}{>{\columncolor{green}}c >{\columncolor{red!80}}c}
     ss &  ss \\
     ss &  ss \\
  \end{array}\,
  \right]
\]

\end{document} 

Output

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.