我在用着这个表生成器我生成了以下表格:
生成器给了我代码:
% Please add the following required packages to your document preamble:
% \usepackage[table,xcdraw]{xcolor}
% If you use beamer only pass "xcolor=table" option, i.e. \documentclass[xcolor=table]{beamer}
\begin{table}[]
\begin{tabular}{|c|c|c|}
\hline
Features & Algorithm 1 & Algorithm 2 \\ \hline
First feature & 0.384 & \cellcolor[HTML]{96FFFB}0.853 \\
Second feature & \cellcolor[HTML]{96FFFB}0.289 & 0.12 \\ \hline
\end{tabular}
\end{table}
我将其输入到 overleaf 代码中。但是输出如下:
你知道为什么我的单元格没有颜色吗?我正在寻找问题所在,但我不知道原因。你知道代码应该是什么样子才能实现这个结果吗?
答案1
\documentclass{article}
\usepackage[table,xcdraw]{xcolor}%<<< added
\begin{document}
\begin{table}[]
\begin{tabular}{|c|c|c|}
\hline
Features & Algorithm 1 & Algorithm 2 \\ \hline
First feature & 0.384 & \cellcolor[HTML]{96FFFB}0.853 \\
Second feature & \cellcolor[HTML]{96FFFB}0.289 & 0.12 \\ \hline
\end{tabular}
\end{table}
\end{document}
答案2
使用tabularray
和siunitx
包的替代解决方案。(作为tabularray
库加载):
\documentclass{article}
\usepackage{xcolor}%<<< added
\usepackage{tabularray}
\UseTblrLibrary{siunitx, varwidth}
\NewTableCommand\SCC[1]{\SetCell{bg=#1}}
\begin{document}
\begin{table}[ht]
\begin{tblr}{hlines, vlines,
colspec={c *{2}{Q[c, si={table-format=1.3}]} },
measure=vbox}
\SCC{yellow!30} Features
& {{{Algorithm 1}}}
& {{{Algorithm 2}}} \\
First feature & 0.384 & \SCC{cyan!30} 0.853 \\
Second feature & \SCC{cyan!30} 0.289
& 0.12 \\
\end{tblr}
\end{table}
\end{document}
答案3
将此指令 \usepackage[table,xcdraw]{xcolor} 放在文档最开始处,紧跟在 \documentclass 之后。它对我来说很管用。