1

I'm trying to create a colored table with something like this code:

\documentclass[a4paper,twoside]{book} 
\usepackage{amsmath}
\usepackage{color}
\usepackage{tabularx}
\usepackage{colortbl}

\pagestyle{empty}
\definecolor{lightblue}{cmyk}{0.5,0,0,0}
\definecolor{lightgrey}{cmyk}{0.25,0,0.25,0}

\begin{document}

\begin{tabularx}{\textwidth}{|X|X|}
  \hline
  \rowcolor{lightblue}
  Item 1 & Item 2 \\ 
  \rowcolor{lightgrey}
  $$A=\left(\begin{smallmatrix}0&0&0\\0&0&0\end{smallmatrix}\right)$$ & 
  $$B=\left(\begin{smallmatrix}1&1&1\\1&1&1\end{smallmatrix}\right)$$ \\
  \hline
\end{tabularx}

\end{document}

But in the second row the first cell is completely black! Why?. I tried to change smallmatrix to matrix but then the cell shows a little black box. I don't understand nothing!

David Carlisle
  • 757,742
Phraellyn
  • 167

1 Answers1

1

It looks like that the row color is reset incorrectly by the line end (\\) in the smallmatrix (\everycr resets the row color globally). You could use code like the following to save and restore the row color around the smallmatrix. This would be worth reporting to the authors of colortbl and amsmath.

\documentclass[a4paper,twoside]{book} 
\usepackage{amsmath}
\usepackage{color}
\usepackage{tabularx}
\usepackage{colortbl}

\pagestyle{empty}
\definecolor{lightblue}{cmyk}{0.5,0,0,0}
\definecolor{lightgrey}{cmyk}{0.25,0,0.25,0}


\makeatletter
\newenvironment{mysmallmatrix}{%
    \let\saved@CT@row@color\CT@row@color
    \begin{smallmatrix}%
}{%
    \end{smallmatrix}%
    \global\let\CT@row@color\saved@CT@row@color
}
\makeatother

\begin{document}

\begin{tabularx}{\textwidth}{|X|X|}
  \hline
  \rowcolor{lightblue}
  Item 1 & Item 2 \\ 
  \rowcolor{lightgrey}
  $\displaystyle A=\left(\begin{mysmallmatrix}0&0&0\\0&0&0\end{mysmallmatrix}\right)$ & 
  $\displaystyle B=\left(\begin{mysmallmatrix}1&1&1\\1&1&1\end{mysmallmatrix}\right)$ \\
  \hline
\end{tabularx}

\end{document}
David Carlisle
  • 757,742
Martin Scharrer
  • 262,582