5

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}

2 Answers 2

4

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

4

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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .