Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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!

share|improve this question
1  
Don't use $$ but single $ for cells. $$ is for display math and greats a paragraph. It should be anyway not be used in modern LaTeX documents, but \[ .. \] instead. –  Martin Scharrer Jul 12 '11 at 11:46
    
I tried to do it, ...with the same result. –  Phraellyn Jul 12 '11 at 12:00
    
I think the problem comes with the arraylike environments –  Phraellyn Jul 12 '11 at 12:03
    
It wasn't meant as solution for this problem, but a general advice. –  Martin Scharrer Jul 12 '11 at 12:08

1 Answer 1

up vote 1 down vote accepted

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}
share|improve this answer
    
Thank you again Martin! now works fine. You save my live two times this week. –  Phraellyn Jul 12 '11 at 12:11
    
I supose I can define mymatrix and myarray environment in this way. Can I? –  Phraellyn Jul 12 '11 at 12:12
    
...Oh, ...the same solution don't work with matrix environment. –  Phraellyn Jul 12 '11 at 12:23

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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