[Tex/LaTex] Tabularx option in tcolorbox: how to colored the first row

rowcolortabularxtcolorbox

I like to have the first row in table make with tcolorbox with tabularx option with different color as it is in the other rows. I try to use \rowcolor{<color>}, but i received error:

Misplaced \noalign.

If I add \\ before \rowcolor{...}, error disappear, however as expected, new empty row is introduced… Is this a bug or do I miss something ? MwE, which show the problem is bellow.

\documentclass[border=5mm,
               preview]{standalone}

    \usepackage[T1]{fontenc}
    \usepackage[utf8]{inputenc}

    \usepackage[dvipsnames,svgnames,table]{xcolor}
    \usepackage{makecell,tabularx}
\newcolumntype{L}{>{\raggedright\arraybackslash}X}
    \usepackage[many]{tcolorbox}
\newtcolorbox{tctabularx}[1]{%
        enhanced,
        fonttitle=\sffamily\bfseries, fontupper=\small\sffamily,
        arc=0mm,
        colback=yellow!10!white, colframe=red!50!black,
        #1                  }% end tctabularx

        \begin{document}
    \begin{tctabularx}{tabularx={L|L}} 
\rowcolor{yellow!30!white}
    \thead{FIR}
    &   \thead{IIR}                         \\
\hline
    končni impulzni odziv $h[n]$
    &   neskončni impulzni odziv $h[n]$     \\
\hline
    sistemska funkcija je polinom
    &   sistemska funkcija je racionalna\newline
        (ulomek dveh polinomov)             \\
\hline
    zahtevnejša izvedba
    &   manj zahtevna izvedba               \\
    \end{tctabularx}
        \end{document}

Best Answer

Try the before upper app={\rowcolor{yellow!30!white} key -- code which is introduced before the first line of tabularx is shipped out.

(See section 18.1 'hooks' of the current (3.72) manual of tcolorbox)

\documentclass[border=5mm,
preview]{standalone}

\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}

\usepackage[dvipsnames,svgnames,table]{xcolor}
\usepackage{makecell,tabularx}
\newcolumntype{L}{>{\raggedright\arraybackslash}X}
\usepackage[many]{tcolorbox}
\newtcolorbox{tctabularx}[1]{%
  enhanced,
  fonttitle=\sffamily\bfseries, fontupper=\small\sffamily,
  arc=0mm,
  colback=yellow!10!white, colframe=red!50!black,
  #1,before upper app={\rowcolor{yellow!30!white}}
                    }% end tctabularx

\begin{document}
\begin{tctabularx}{tabularx={L|L}} 
  \thead{FIR}
  &   \thead{IIR}                         \\
  \hline
  končni impulzni odziv $h[n]$
     &   neskončni impulzni odziv $h[n]$     \\
     \hline
     sistemska funkcija je polinom
     &   sistemska funkcija je racionalna\newline
     (ulomek dveh polinomov)             \\
     \hline
     zahtevnejša izvedba
     &   manj zahtevna izvedba               \\
   \end{tctabularx}
 \end{document}

enter image description here

Related Question