2

I want to fill the box but \cellcolor{red} doesn't work.

enter image description here

\documentclass{article}
\usepackage{float}
\usepackage{array, makecell}
\setcellgapes{5pt}

\begin{document}

\makegapedcells \begin{tabular}{|c|c|c|c|} \hline \cellcolor{red}1&1&1&1\ \hline 1&1&1&1\ \hline 1&1&1&1\ \hline 1&1&1&1\ \hline 1&1&1&1\ \hline

\end{tabular}

\end{document}

user202729
  • 7,143
Pitaya88
  • 377
  • Well it did raise "Undefined control sequence" for the cellcolor command there... Make sure that your minimal working example is correct, you need to add \usepackage[table]{xcolor}. ■ Using https://tex.stackexchange.com/questions/185674/how-to-see-which-package-define-a-particular-command-macro you can figure out which package the commands belong to (colortbl), and figure out the issue is that makegapedcell conflicts with cellcolor in colortbl. – user202729 Dec 20 '21 at 05:34

3 Answers3

5

Just load the colortbl package – or xcolorwith option [table]:

\documentclass[12pt]{article}
\usepackage{array}
\usepackage{cellspace}
\usepackage[table, svgnames]{xcolor}
\setlength{\cellspacetoplimit}{5pt}
\setlength{\cellspacebottomlimit}{5pt}

\begin{document}

\begin{center} \setlength{\arrayrulewidth}{1pt} \arrayrulecolor{LightSteelBlue} \begin{tabular}{|Sc|Sc|Sc|} \hline \cellcolor{Tomato}$1$ & $1$ & $1$ \ \hline 1 & 1 & 1 \ \hline 1 & 1 & 1 \ \hline 1 & 1 & 1 \ \hline \end{tabular} \end{center}

\end{document}

enter image description here

Bernard
  • 271,350
3

In case that you would use [my answer][1] then for coloring od some cell you only need to add the following attribute to this cell:

\SetCell{bg=<name of desired color>}

because in my answer for coloring of rules is already used xcolor package. So your matrix ca be write as:

\documentclass[12pt, border=3mm]{standalone}
\usepackage{xcolor}
\usepackage{tabularray}

\begin{document}

\begin{tblr}{hlines={1pt,teal}, vlines={1pt,teal}, colspec={*{3}{c}}, belowsep=0pt } \SetCell{bg=red} 1 & 1 & 1 \ 1 & 1 & 1 \ 1 & 1 & 1 \ 1 & 1 & 1 \ \end{tblr}

\end{document}

enter image description here

Zarko
  • 296,517
3

I think it is a kind of solution:

enter image description here

\documentclass{article}
\usepackage[table]{xcolor}
\usepackage{nicematrix}
\NiceMatrixOptions{cell-space-top-limit=5pt,cell-space-bottom-limit=5pt}

\begin{document} \begin{table}[htbp] \centering \begin{NiceTabular}{|c|c|c|} \hline \cellcolor{red}1& 1 & 1 \ \hline 1 & 1 & 1 \ \hline 1 & 1 & 1 \ \hline \end{NiceTabular} \end{table} \end{document}

WinnieNotThePooh
  • 3,008
  • 1
  • 7
  • 14