我想填满盒子但是\cellcolor{red}
不行。
\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}
答案1
我认为这是一种解决方案:
\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}
答案2
只需加载colortbl
包 – 或者xcolor
使用选项[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}
答案3
如果您要使用[我的答案][1],那么为了给某个单元格着色,您只需要向该单元格添加以下属性:
\SetCell{bg=<name of desired color>}
因为在我的回答中,规则的着色已经使用了xcolor
包。所以你的矩阵可以写成:
\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][2]][2]
[1]: https://tex.stackexchange.com/questions/625660/tabular-centering/625669#625669
[2]: https://i.stack.imgur.com/P7q9E.png