[Tex/LaTex] Problems for coloring tables using booktabs and xcolor

booktabscolorsiunitxtabularx

Well, recently I posted a question related here. Thanks to the solution suggested by Harish Kumar I could fix the two tables posted at first. Later I tried to apply the solution to a new third table. This table is like two tables in one, so I try to start the colouring of the rows until the 5th row for let the headers in white. The problem is that I can't get a nice result using the columntypes C or Y defined in the preamble, if I use them again I've got colour blocks wider than rulers but also \rowcolor starts not in the 5th but in the 1st row. Also I'm not sure the column S would be the best choice for this table, but the idea is to align the contents using the decimal mark (point).

\documentclass[fontsize=10pt,paper=letter,headings=big,bibliography=totoc,DIV=8]{scrbook}
\KOMAoptions{headsepline=true,draft=false}
\usepackage{typearea}
\usepackage[usenames,dvipsnames,x11names,table]{xcolor}
\usepackage[spanish,mexico]{babel}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[sc,osf]{mathpazo}
\usepackage{array,multirow,tabularx,ragged2e,booktabs}
\newcolumntype{Y}{>{\RaggedRight\arraybackslash\hspace{0pt}}X}
\newcolumntype{C}{>{\centering\arraybackslash\hspace{0pt}}X}
\usepackage{rotating}
\usepackage{colortbl}
\usepackage[per-mode=symbol]{siunitx}
\DeclareSIUnit\poise{P}
\DeclareSIUnit\stokes{St}

\begin{document}

\begin{table}[h!tb]
\caption[Componentes de Fourier y sus correspondientes valores de $\alpha$]{Componentes de Fourier y los valores correspondientes del parámetro adimensional $\alpha$ para formas de onda de flujo registradas a partir de las arterias carótidas y femorales comunes de un sujeto joven. Los valores de $v_p$ se han normalizado a $v_0$, y el ángulo $\varphi_p$ está dada en grados desde un punto de partida arbitrario.}
\label{tab:fouriercomp}
\centering
\rowcolors{5}{}{lightgray!20}
\begin{tabularx}{3.1in}{@{\kern\tabcolsep}CCS[table-format=2.1]S[table-format=1.2]Y<{\kern\tabcolsep}}          
\toprule
\multicolumn{5}{c}{Femoral común}\\
\multicolumn{5}{p{3.1in}}{(diámetro: \SI{8.4}{\milli\metre}; frecuencia cardíaca: 62 latidos/min;} \\
\multicolumn{5}{l}{viscosidad: \SI{0.038}{\stokes})}\\ %\hline
\midrule
Armónico & Frecuencia & $\alpha$ & $v_p$ & $\varphi_p$ \\
\midrule
0 & {-}  & {-}  & 1.00 & {-} \\
1 & 1.03 &  5.5 & 1.89 &  32 \\
2 & 2.05 &  7.7 & 2.49 &  85 \\
3 & 3.08 &  9.5 & 1.28 & 156 \\
4 & 4.10 & 10.9 & 0.32 & 193 \\
5 & 5.13 & 12.2 & 0.27 & 133 \\
6 & 6.15 & 13.4 & 0.32 & 155 \\
7 & 7.18 & 14.5 & 0.28 & 195 \\
8 & 8.21 & 15.5 & 0.01 & 310 \\
\midrule
\rowcolor{white} \multicolumn{5}{C}{Carótida común}\\
\rowcolor{white}\multicolumn{5}{Y}{(diámetro: \SI{6.0}{\milli\metre}; frecuencia cardíaca: 62 latidos/min;}\\
\rowcolor{white} \multicolumn{5}{Y}{viscosidad: \SI{0.038}{\stokes})}\\ %\hline
\midrule \rowcolor{white}
Armónico & Frecuencia & $\alpha$ & $v_p$ & $\varphi_p$ \\
\midrule
0 & {-}  & {-}  & 1.00 & {-} \\
1 & 1.03 &  3.9 & 0.33 &  74 \\
2 & 2.05 &  5.5 & 0.24 &  79 \\
3 & 3.08 &  6.8 & 0.24 & 124 \\
4 & 4.10 &  7.8 & 0.12 & 146 \\
5 & 5.13 &  8.7 & 0.11 & 147 \\
6 & 6.15 &  9.6 & 0.13 & 179 \\
7 & 7.18 & 10.3 & 0.06 & 233 \\
8 & 8.21 & 12.4 & 0.04 & 218 \\
\bottomrule
\end{tabularx}      
\end{table}
\end{document}

Since the headers of both tables are almost the same, I should the different approaches I tried before without nice results.

enter image description here

Best Answer

May I propose to simplify your table? You do not need all these special columns in my eyes. The trick used here is to reset the row numbers which are used by the table option of xcolor. The credits for this go to Heiko Oberdiek.

% arara: pdflatex

\documentclass[fontsize=10pt,paper=letter,DIV=8]{scrbook}
\KOMAoptions{headsepline=true}
\usepackage[table]{xcolor}
\usepackage[spanish,mexico]{babel}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[sc,osf]{mathpazo}
\usepackage{booktabs}
\usepackage[per-mode=symbol]{siunitx}
\DeclareSIUnit\stokes{St}

\makeatletter
\@ifundefined{c@rownum}{%
    \let\c@rownum\rownum
}{}
\@ifundefined{therownum}{%
    \def\therownum{\@arabic\rownum}%
}{}
\makeatother

\begin{document}

    \begin{table}[h!tb]
        \centering%
        \caption[Componentes de Fourier y sus correspondientes valores de $\alpha$]{Componentes de Fourier y los valores correspondientes del parámetro adimensional $\alpha$ para formas de onda de flujo registradas a partir de las arterias carótidas y femorales comunes de un sujeto joven. Los valores de $v_p$ se han normalizado a $v_0$, y el ángulo $\varphi_p$ está dada en grados desde un punto de partida arbitrario.}%
        \label{tab:fouriercomp}%    
        \rowcolors{4}{gray!20}{}%
        \begin{tabular}{%
                S[table-format=1.0]
                S[table-format=1.2]
                S[table-format=2.1]
                S[table-format=1.2]
                S[table-format=3.0]
                }          
            \toprule
            \multicolumn{5}{c}{\textsc{Femoral común}} \\
            \multicolumn{5}{p{2.4in}}{(diámetro: \SI{8.4}{\milli\metre}; frecuencia cardíaca: \SI{62}{latidos\per\minute}; viscosidad: \SI{0.038}{\stokes})} \\ 
            \midrule
            {Armónico} & {Frecuencia} & $\alpha$ & $v_p$ & $\varphi_p$ \\
            \midrule
            0 & {-}  & {-}  & 1.00 & {-} \\
            1 & 1.03 &  5.5 & 1.89 &  32 \\
            2 & 2.05 &  7.7 & 2.49 &  85 \\
            3 & 3.08 &  9.5 & 1.28 & 156 \\
            4 & 4.10 & 10.9 & 0.32 & 193 \\
            5 & 5.13 & 12.2 & 0.27 & 133 \\
            6 & 6.15 & 13.4 & 0.32 & 155 \\
            7 & 7.18 & 14.5 & 0.28 & 195 \\
            8 & 8.21 & 15.5 & 0.01 & 310 {\setcounter{rownum}{0}} \\
            \midrule
            \multicolumn{5}{c}{\textsc{Carótida común}}\\
            \multicolumn{5}{p{2.4in}}{(diámetro: \SI{6.0}{\milli\metre}; frecuencia cardíaca: \SI{62}{latidos\per\minute}; viscosidad: \SI{0.038}{\stokes})} \\
            \midrule
            {Armónico} & {Frecuencia} & $\alpha$ & $v_p$ & $\varphi_p$ \\
            \midrule
            0 & {-}  & {-}  & 1.00 & {-} \\
            1 & 1.03 &  3.9 & 0.33 &  74 \\
            2 & 2.05 &  5.5 & 0.24 &  79 \\
            3 & 3.08 &  6.8 & 0.24 & 124 \\
            4 & 4.10 &  7.8 & 0.12 & 146 \\
            5 & 5.13 &  8.7 & 0.11 & 147 \\
            6 & 6.15 &  9.6 & 0.13 & 179 \\
            7 & 7.18 & 10.3 & 0.06 & 233 \\
            8 & 8.21 & 12.4 & 0.04 & 218 \\
            \bottomrule
        \end{tabular}      
    \end{table}
\end{document}

enter image description here

Related Question