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 tried to use \cellcolor as suggested in color only a cell of a table but it didn't work. Can it be done?

That's my code:

\documentclass{beamer}
\usepackage{colortbl,xcolor}
\newcommand\y{\cellcolor{green!10}}

\begin{document}
   \[ \bordermatrix{
        & X_1 & X_2 & X_3 \cr
        & 1 & \y 2 & 3 \cr
            & 1 & 2 & 3 \cr
                & 1 & 2 & 3 \cr
                    & 1 & 2 & 3 \cr
                        & 1 & 2 & 3  }   \]
\end{document}
share|improve this question

2 Answers 2

up vote 3 down vote accepted

You can use the kbordermatrix package (not on CTAN, you can download it from the link I provided) and its \kbordermatrix command instead and wrap the \cellcolor inside a \multicolumn:

\documentclass{beamer}
\usepackage{colortbl,xcolor}
\usepackage{kbordermatrix}
\newcommand\y{\cellcolor{green!20}}

\renewcommand\kbldelim{(}
\renewcommand\kbrdelim{)}

\begin{document}

\begin{frame}
   \[ \kbordermatrix{
        & X_1 & X_2 & X_3 \cr
        & 1 & \multicolumn{1}{c}{\y 2} & 3 \cr
            & 1 & \multicolumn{1}{c}{\cellcolor{red!20}2} & 3 \cr
                & 1 & \multicolumn{1}{c}{\cellcolor{olive!20}2} & 3 \cr
                    & 1 & \multicolumn{1}{c}{\cellcolor{blue!20}2} & 3 \cr
                        & 1 & \multicolumn{1}{c}{\cellcolor{orange!20}2} & 3  }   \]
\end{frame}

\end{document}

enter image description here

Another option is to use the blkarray package instead and, again, place the color inside a \multicolumn:

\PassOptionsToPackage{table}{xcolor}
\documentclass{beamer}
\usepackage{blkarray}
\newcommand\y{\cellcolor{green!20}}

\begin{document}

\begin{frame}
\[
\begin{blockarray}{ccc}
X_1 & X_2 & X_3 \\
\begin{block}{(ccc)}
1 & \multicolumn{1}{c}{\cellcolor{blue!20}2} & 3 \\
1 & \multicolumn{1}{c}{\y 2} & 3 \\
1 & \multicolumn{1}{c}{\cellcolor{red!20}2} & 3 \\
\end{block}
\end{blockarray}
\]
\end{frame}

\end{document}

enter image description here

share|improve this answer

What about a simple \colorbox?

\documentclass[xcolor=table]{beamer}
\newcommand\y[1]{%
  \colorbox{green!10}{$#1$}%
}

\begin{document}
  \[
    \bordermatrix{
      & X_1 & X_2 & X_3 \cr
      & 1 & \y{2} & 3 \cr
      & 1 & 2 & 3 \cr
      & 1 & 2 & 3 \cr
      & 1 & 2 & 3 \cr
      & 1 & 2 & 3
    }
  \]
\end{document}

Result

share|improve this answer

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.