6

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}

2 Answers 2

7

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

2
  • I read this section in manual, but now I see I didn't understand description, that this can be use for coloring of the first row of table. Thanks for help! Now It works!
    – Zarko
    Sep 27, 2015 at 17:56
  • @Zarko: Yes, it's a little bit unclear there
    – user31729
    Sep 27, 2015 at 17:56
6

enter image description here

\documentclass{article}   
   \usepackage[T1]{fontenc}
    \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}}
\cellcolor{yellow!30!white}
    \thead{FIR}
    &  \cellcolor{yellow!30!white} \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}

You would use \cellcolor instead in this case. This is because tcolorboxes are considered to be more like cells rather than multi-cells (row).

5
  • Nice solution too!!! (+1)
    – user31729
    Sep 27, 2015 at 17:52
  • @ChristianHupfer Thank you, where is the missing ` \ `?
    – AboAmmar
    Sep 27, 2015 at 17:55
  • @ChristianHupfer Haha ... lack of coffee ;-)
    – AboAmmar
    Sep 27, 2015 at 17:57
  • @AboAmmar, now I'm confused. I try this (well, not in my MWE, in real document) ant this doesn't work. It seems, that in real document I has some other error ... which I need now to sorted out. With help of your and Christian answer this will be now more easy.
    – Zarko
    Sep 27, 2015 at 18:00
  • @AboAmmar: There's a German proverb for this: "Das hätte ich jetzt auch gesagt -- I would have said this just now too" ... of course we know that it's not meant seriously ;-)
    – user31729
    Sep 27, 2015 at 18:02

You must log in to answer this question.

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