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 Answer 1

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} 
3
  • 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? Commented Jun 4, 2017 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. Commented Jun 4, 2017 at 11:51
  • You are probably right. I end up using scalebox when there's a need for coloring a row in the matrix. Commented Jun 9, 2017 at 9:29

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.