1

I'm trying to color a single cell in smallmatrix, but it seems to me that the \cellcolor doesn't work in smallmatrix:

\documentclass{article}
\usepackage{amsmath} %smallmatrix
\usepackage[table]{xcolor} %cellcolor
\begin{document}
\[
\left(\begin{array}{cc}
\cellcolor{gray}1&2
\end{array}\right)
    \quad
\left(\begin{smallmatrix}
\cellcolor{gray}1&2
\end{smallmatrix}\right)
\]
\end{document}

arrat vs smallmatrix

You can see that the array is colored as desired while in smallmatrix \cellcolor doesn't do anything.

Does anyone know how to do color cells in smallmatrix?

1

You need to use the \colorbox macro. And, since the \colorbox macro typesets its second argument in text mode (and text style), be sure to encase the second argument in a $\scriptstyle ...$ "wrapper".

$(\begin{smallmatrix}
\colorbox{lightgray}{$\scriptstyle 1$}&2
\end{smallmatrix})$

A full MWE: (mininimum working example):

enter image description here

\documentclass{article}
\usepackage{amsmath}       % smallmatrix env.
\usepackage[table]{xcolor} % \cellcolor, \colorbox
\begin{document}

$\left(\begin{array}{cc}
\cellcolor{lightgray}1&2
\end{array}\right)$

$(\begin{smallmatrix}
\colorbox{lightgray}{$\scriptstyle 1$}&2
\end{smallmatrix})$

\end{document}
  • Thanks! A further question: if I want to color an entire row in smallmatrix, I can do it cell-by-cell as you suggested. Is there a \colorbox analogue to \rowcolor? – Chun-Ju Lai Jun 4 '17 at 9:26
  • @Chun-JuLai - You may be abusing the entire design philosophy of smallmatrix if you start coloring entire rows. I certainly wouldn't do it. – Mico Jun 4 '17 at 11:51
  • You are probably right. I end up using scalebox when there's a need for coloring a row in the matrix. – Chun-Ju Lai Jun 9 '17 at 9:29

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.