0

I'm using this table generator and I generated this table:

enter image description here

Generator gave me code:

% 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}

which I entered to my overleaf code. However the output is the following:

enter image description here

Do you know why I don't have my cells colored? I was looking there is the problem but I have no idea why. Do you know how code should look like to achieve this result?

8
  • Welcome to TeX.SE! Have you loaded package xcolor?
    – Mensch
    Dec 7, 2021 at 14:36
  • Yes I did, I used command \usepackage[table,xcdraw]{xcolor} at the beginning of document. Is there anything more that I have to do?
    – John
    Dec 7, 2021 at 14:38
  • Which document class do you use? Dec 7, 2021 at 14:45
  • 1
    please provide a small but complete document that fails to colour the table, we can not debug the fragment provided the output you show would indicate that xcolor package is not loaded. Dec 7, 2021 at 15:03
  • 1
    Apart from a float warning LaTeX Warning: No positions in optional float specifier., your code runs well on overleaf's texlive2021, with \documentclass{article} \usepackage[table,xcdraw]{xcolor}. Dec 8, 2021 at 7:54

3 Answers 3

1

enter image description here

\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}
1
  • 1
    According to a comment from the asker (tex.stackexchange.com/questions/625246/…) they already tried this and it did not work. Possibly they already had a previous \usepackage{xcolor} statement somewhere, even though they claim there are no errors when compiling. In any case, your answer does not seem to solve the actual problem in this question (and neither does the answer of Johnsonn), even though your code is correct in itself.
    – Marijn
    Mar 1, 2022 at 9:44
1

An alternative solution with using tabularray and siunitx package. (loaded as tabularray library):

\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}

enter image description here

0

Put this instruction \usepackage[table,xcdraw]{xcolor} at the very beginning of the document juste after \documentclass. It just worked for me.

1
  • 1
    As it’s currently written, your answer is unclear. Please edit to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers in the help center.
    – Community Bot
    Mar 1, 2022 at 9:13

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