2

I'm trying to color the cells of the matrix which have nonnull entries, but it seems that \cellcolor doesn't work. There is any solution to this? Moreover, the vertical dots of the first column (outside the matrix) have normal size. My code is the following:

\documentclass[10pt,xcolor={dvipsnames,table}]{beamer}

\mode<article> % only for the article version
{
  \usepackage{fullpage}
  \usepackage{hyperref}
}


\mode<presentation>
{
  %\setbeamertemplate{background canvas}[vertical shading][bottom=red!10,top=blue!10]
  \setbeamercovered{transparent}
  \usefonttheme{serif}
  \usecolortheme{crane}
}

\setbeamercovered{dynamic}
\setbeamertemplate{items}[circle]

\usepackage[table]{xcolor}
\usepackage{amsmath}
\usepackage{kbordermatrix}
\usepackage{tikz}
\usetikzlibrary{tikzmark}

\newcommand\x{\times}


\begin{document}

\begin{frame}

\begin{equation*}
\kbordermatrix{
  & 2^{0} & 2^{1} & & 2^{2} & \ldots & 2^{m} & \ldots & n & \ldots & 2^{m+1} & \ldots \\
  2^{0} & {\cellcolor{orange}1} & 0 & 0 & \ldots & \ldots & 0 & 0 & \ldots & 0 & \ldots & \ldots \\
  2^{1} & 0 & {\cellcolor{orange}1} & {\cellcolor{orange}1} & \ldots & \ldots & 0 & 0 & \ldots & 0 & \ldots & \ldots \\
  & 0 & {\cellcolor{orange}1} & {\cellcolor{orange}-1} & \ldots & \ldots & 0 & 0 & \ldots & 0 & \ldots & \ldots \\
  2^{2} & \vdots & \vdots & \vdots & \ddots & & \vdots & \vdots & & \vdots & \\
  \vdots & \vdots & \vdots & \vdots & & \ddots & \vdots & \vdots & & \vdots & \\
  2^{m} & 0 & 0 & 0 & \ldots & \ldots & {\cellcolor{orange}\x} & {\cellcolor{orange}\x} & {\cellcolor{orange}\ldots} & {\cellcolor{orange}\x} & \ldots & \ldots \\
  \vdots & 0 & 0 & 0 & \ldots & \ldots & {\cellcolor{orange}\x} & {\cellcolor{orange}\x} & {\cellcolor{orange}\ldots} & {\cellcolor{orange}\x} & \ldots & \ldots \\
  k & \vdots & \vdots & \vdots & &        & {\cellcolor{orange}\vdots} & {\cellcolor{orange}\vdots} & {\cellcolor{orange}\ddots} & {\cellcolor{orange}\vdots} & \\
  \vdots & 0 & 0 & 0 & \ldots & \ldots & {\cellcolor{orange}\x} & {\cellcolor{orange}\x} & {\cellcolor{orange}\ldots} & {\cellcolor{orange}\x} & \ldots & \ldots \\
  2^{m+1} & \vdots & \vdots & \vdots & & & \vdots & \vdots & \vdots & \vdots & \ddots & \\
  \vdots & \vdots & \vdots & \vdots & & & \vdots & \vdots & \vdots & \vdots & & \ddots
  }
\end{equation*}

\end{frame}

\end{document}
1
  • Does answer on your previous question not help you at this problem?
    – Zarko
    Commented Apr 16, 2023 at 19:59

2 Answers 2

2

If you like to use kbordermatrix than you faced with problem with coloring of some matrix cells. First, in it \cellcolor doesn't work, since it is intended for tables, second, possible solution is to use colorbox, but result is not pleasant:

enter image description here

\documentclass[10pt,xcolor={dvipsnames,table}]{beamer}
\setbeamercovered{dynamic}
\setbeamertemplate{items}[circle]

\usepackage[table]{xcolor}
\usepackage{kbordermatrix}
\usepackage{tikz}
\usetikzlibrary{tikzmark}
\usepackage{amsmath}
\newcommand\x{$\times$}
\newcommand\CB[1]{\colorbox{orange!30}{#1}}

\begin{document}

\begin{frame}

\[
\kbordermatrix{
        & 2^{0}  & 2^{1}  &         & 2^{2}  & \ldots & 2^{m}   & \ldots & n      & \ldots & 2^{m+1} & \ldots \\
2^{0}   & \CB{1} & 0      & 0       & \ldots & \ldots & 0       & 0      & \ldots & 0      & \ldots  & \ldots \\
2^{1}   & 0      & \CB{1} & \CB{1}  & \ldots & \ldots & 0       & 0      & \ldots & 0      & \ldots  & \ldots \\
        & 0      & \CB{1} & \CB{-1} & \ldots & \ldots & 0       & 0      & \ldots & 0      & \ldots  & \ldots \\
2^{2}   & \vdots & \vdots & \vdots  & \ddots &        & \vdots  & \vdots &        & \vdots & \\
\vdots  & \vdots & \vdots & \vdots  &        & \ddots & \vdots  & \vdots &        & \vdots & \\
2^{m}   & 0      & 0      & 0       & \ldots & \ldots & \CB{\x} &\CB{\x} & \CB{$\ldots$} 
                                                                                  &\CB{\x} & \ldots & \ldots  \\
\vdots  & 0      & 0      & 0       & \ldots & \ldots & \CB{\x} &\CB{\x} & \CB{$\ldots$} 
                                                                                  &\CB{\x} & \ldots & \ldots  \\
k       & \vdots & \vdots & \vdots  &        &        & \CB{$\vdots$} 
                                                                &\CB{$\vdots$} 
                                                                         &\CB{$\ddots$} 
                                                                                  & \CB{$\vdots$}     &         \\
\vdots  & 0      & 0      & 0       & \ldots & \ldots & \CB{\x} &\CB{\x} &\CB{$\ldots$} 
                                                                                  &\CB{\x} & \ldots & \ldots  \\
2^{m+1} & \vdots & \vdots & \vdots  &        &        & \vdots  & \vdots & \vdots & \vdots & \ddots &         \\
\vdots  & \vdots & \vdots & \vdots  &        &        & \vdots  & \vdots & \vdots & \vdots &        & \ddots
  }
\]

\end{frame}

\end{document}

Edit: For nicer result you should stick wit suggestion given in my answer to your previous question:

\documentclass[10pt,xcolor={dvipsnames,table}]{beamer}
\setbeamercovered{dynamic}
\setbeamertemplate{items}[circle]

\usepackage{tikz}
\usetikzlibrary{fit,
                matrix,
                positioning}
\tikzset{baseline = (current bounding box.center),
node distance= 1mm and 2mm,
    M/.style = {matrix of math nodes,
                nodes in empty cells,
                nodes={minimum size=2em, inner sep=4pt, anchor=center},
                column sep=2pt, row sep=2pt,
                inner xsep=2pt, inner ysep=-2pt
                },
   CB/.style = {fill=orange!50},
  lbl/.style = {text=gray, left=of #1}
        }
\newcommand\svd{\raisebox{-2ex}{$\smash\vdots$}}
\newcommand\sdd{\raisebox{-2ex}{$\smash\ddots$}}
\newcommand\x{\times}

\begin{document}

\begin{frame}[fragile]
\[
\mathbf{D} = \tikz{
\matrix (n) [M, left delimiter={[},right delimiter={]}]
{
|[CB]| 1     
      & 0        & 0        & \ldots        & 0            & 0             & \ldots        & 0      & \ldots  & \ldots  \\
0     & |[CB]| 1 & |[CB]| 1 & \ldots        & 0            & 0             & \ldots        & 0      & \ldots  & \ldots  \\
0     & |[CB]| 1 & |[CB]| -1& \ldots        & 0            & 0             & \ldots        & 0      & \ldots  & \ldots  \\
\svd  & \sdd     & \svd     & |[CB]| \svd   & |[CB]| \svd  & |[CB]| \svd   & |[CB]| \svd   & \svd   & \ldots  & \ldots  \\
0     & 0        & 0        & |[CB]| \ldots & |[CB]| \x    & |[CB]| \x     & |[CB]| \ldots & \x     & \ldots  & \ldots  \\
0     & 0        & 0        & |[CB]| \ldots & |[CB]| \x    & |[CB]| \x     & |[CB]| \ldots & \x     & \ldots  & \ldots  \\
\svd  & \svd     &          & |[CB]| \svd   & |[CB]| \svd  & |[CB]| \sdd   & |[CB]| \svd   &        &         &         \\
0     & 0        & 0        & \ldots        & \x           & \x            & \ldots        & \x     & \ldots  & \ldots  \\
\svd  & \svd     & \svd     &               & \svd         & \svd          & \svd          & \svd   & \sdd    &         \\
\svd  & \svd     & \svd     &               & \svd         & \svd          & \svd          & \svd   &         & \sdd    \\
};
\node[lbl=n-1-1.west] {$2^{0}$};
\node[lbl=n-2-1] {$2^{1}$}; 
\node[lbl=n-3-1] {$2^{2}$}; 
\node[lbl=n-4-1] {$\svd$}; 
\node[lbl=n-5-1] {$2^{m}$}; 
\node[lbl=n-6-1] {$\svd$};
\node[lbl=n-7-1] {$k$};      
\node[lbl=n-8-1] {$\svd$}; 
\node[lbl=n-9-1] {$2^{m+1}$}; 
\node[lbl=n-10-1] {$\svd$};  
%
   }% end of tikz
\]
\end{frame}

\end{document}

enter image description here

2

With {bNiceMatrix} of nicematrix.

\documentclass[10pt,xcolor=dvipsnames]{beamer}
\setbeamercovered{dynamic}
\setbeamertemplate{items}[circle]

\usepackage{xcolor}
\usepackage{nicematrix}



\newcommand\x{\times}
\newcommand\CB[1]{\Block[fill=orange!30,draw=white,line-width=1pt]{}{#1}}

\begin{document}

\begin{frame}

\setcounter{MaxMatrixCols}{12}
\renewcommand{\arraystretch}{1.2}

\[
\begin{bNiceMatrix}[first-row,first-col,margin]
        & 2^{0}  & 2^{1}  &         & 2^{2}  & \ldots & 2^{m}   & \ldots & n      & \ldots & 2^{m+1} & \ldots \\
2^{0}   & \CB{1} & 0      & 0       & \ldots & \ldots & 0       & 0      & \ldots & 0      & \ldots  & \ldots \\
2^{1}   & 0      & \CB{1} & \CB{1}  & \ldots & \ldots & 0       & 0      & \ldots & 0      & \ldots  & \ldots \\
        & 0      & \CB{1} & \CB{-1} & \ldots & \ldots & 0       & 0      & \ldots & 0      & \ldots  & \ldots \\
2^{2}   & \vdots & \vdots & \vdots  & \ddots &        & \vdots  & \vdots &        & \vdots & \\
\vdots  & \vdots & \vdots & \vdots  &        & \ddots & \vdots  & \vdots &        & \vdots & \\
2^{m}   & 0      & 0      & 0       & \ldots & \ldots & \CB{\x} &\CB{\x} & \CB{\ldots} 
                                                                                  &\CB{\x} & \ldots & \ldots  \\
\vdots  & 0      & 0      & 0       & \ldots & \ldots & \CB{\x} &\CB{\x} & \CB{\ldots} 
                                                                                  &\CB{\x} & \ldots & \ldots  \\
k       & \vdots & \vdots & \vdots  &        &        & \CB{\vdots} 
                                                                &\CB{\vdots} 
                                                                         &\CB{\ddots} 
                                                                                  & \CB{\vdots}     &         \\
\vdots  & 0      & 0      & 0       & \ldots & \ldots & \CB{\x} &\CB{\x} &\CB{\ldots} 
                                                                                  &\CB{\x} & \ldots & \ldots  \\
2^{m+1} & \vdots & \vdots & \vdots  &        &        & \vdots  & \vdots & \vdots & \vdots & \ddots &         \\
\vdots  & \vdots & \vdots & \vdots  &        &        & \vdots  & \vdots & \vdots & \vdots &        & \ddots
\end{bNiceMatrix}
\]

\end{frame}

\end{document}

Output of the above code

You must log in to answer this question.

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