1

How to color rows in this table please? I tried

\rowfont{\color{red}}

but I did some mistake.

\documentclass[12pt,a4paper,hidelinks]{report}
\usepackage[czech]{babel}
\usepackage[output-decimal-marker={,}]{siunitx}
\usepackage{makecell}
\usepackage{booktabs}
\usepackage{empheq}
\usepackage[most]{tcolorbox}

\begin{document}

\begin{table}[!h]
\small

\label{porovnani}
\renewcommand{\arraystretch}{1.2}
\setlength\tabcolsep{7pt}
\begin{tabular*}{\linewidth}{cccS[table-format=2.2]S[table-format=2.2]S[table-format=2.2]}
\Xhline{1.2pt}\noalign{\vskip 0.4ex}\Xhline{1.2pt}%
&&&&\\[-10pt]
{} & {A}&   {B}&    {C}&    {B}&    {E}\\
&&&&\\[-10pt]
\Xhline{1.2pt}\noalign{\vskip 0.4ex}
B  & \multirow{2}{*}{A}& \multirow{4}{*}{B}&    21,95&  7,59&   3,19\\
    1 & & & 4,45&   5,85&   11,87\\
1 & 2& 3&   4,45&   5,85&   11,87\\
\Xhline{1.2pt}
\end{tabular*}

\end{table}

\end{document}
4
  • 2
    The \rowfont command is only available inside of a tabu environment. If you want a solution that does not rely on the tabu package, you might want to have a look at this answer: tex.stackexchange.com/a/26364/134144
    – leandriis
    Commented Jun 3, 2019 at 6:56
  • Thank you and when I have a \multirow{4}{*}{a2} in table it is balck then. I would like to skip the multirow cell but than have a red rest of row. Commented Jun 3, 2019 at 7:29
  • Would you please change your question? As far as I understand, you asked how to color a whole row, or am I mistaken?
    – Keks Dose
    Commented Jun 3, 2019 at 7:38
  • Yes, I editted it and yes I ask for color a whole row. I can't color one cell because it disturb a siunix format. Commented Jun 3, 2019 at 8:51

1 Answer 1

2
  • For coloring rows you need first to load colortbl or better xcolor package with option table.
  • It is not clear, which rows you like to have colored
  • Your code for table is frankly said strange. I try to correct it but I'm lost in it (how you use multirow), so temporary result is the following:

enter image description here

\documentclass[12pt,a4paper,hidelinks]{report}
\usepackage[czech]{babel}
\usepackage[output-decimal-marker={,}]{siunitx}
\usepackage[table]{xcolor}
\usepackage{booktabs, 
            makecell,
            multirow}
\usepackage{empheq}
\usepackage[most]{tcolorbox}

\begin{document}
    \begin{table}[!h]
    \small
    \label{porovnani}   % this not work without use of "caption"
\renewcommand{\arraystretch}{1.2}
\setlength\tabcolsep{7pt}
\begin{tabular*}{\linewidth}{ccc *{3}{S[table-format=2.2]} }
    \Xhline{1.2pt}
\rowcolor{red}
    & {A}   & {B}   & {C}   & {B}   & {E}       \\
    \Xhline{1.2pt} 
B  & \multirow{2}{*}{A} 
            & \multirow{3}{*}{B}
                    & 21,95 & 7,59  & 3,19      \\
1   &       &       & 4,45  & 5,85  & 11,87     \\
1   & 2     &       & 4,45  & 5,85  & 11,87     \\
    \Xhline{1.2pt}
\end{tabular*}
    \end{table}
\end{document}

  • I would not use tabular* but simple tabular and center table in float environment:

enter image description here

\documentclass[12pt,a4paper,hidelinks]{report}
\usepackage[czech]{babel}
\usepackage[output-decimal-marker={,}]{siunitx}
\usepackage[table]{xcolor}
\usepackage{booktabs, 
            makecell,
            multirow}
\usepackage{empheq}
\usepackage[most]{tcolorbox}

\begin{document}
    \begin{table}[!h]
    \centering
    \label{porovnani}   % this not work without use of "caption"
\renewcommand{\arraystretch}{1.2}
\setlength\tabcolsep{7pt}
\begin{tabular}{ccc *{3}{S[table-format=2.2]} }
    \Xhline{1.2pt}
\rowcolor{red}
    & {A}   & {B}   & {C}   & {B}   & {E}       \\
    \Xhline{1.2pt} 
B  & \multirow{2}{*}{A} 
            & \multirow{3}{*}{B}
                    & 21,95 & 7,59  & 3,19      \\
1   &       &       & 4,45  & 5,85  & 11,87     \\
1   & 2     &       & 4,45  & 5,85  & 11,87     \\
    \Xhline{1.2pt}
\end{tabular}
    \end{table}
\end{document}
2
  • And is it possible to use \textcolor and have align S[table-format=2.2] Commented Jun 4, 2019 at 3:47
  • @LukášAltman, of course it is possible. Do you like to have colored numbers in S columns? All in one column or only some of them? You need to change accordingly S column specification, for example S[color=red]. See siunitx documentation, last example on page 14.
    – Zarko
    Commented Jun 4, 2019 at 6:31

You must log in to answer this question.

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