0

Below is a sample of my table and I just can't make out why it is behaving the way it does. Before applying rowcolor everything works fine.

\documentclass[a4paper]{scrreprt}
\usepackage{siunitx,booktabs}
\usepackage{tabu}
\usepackage{graphicx}
\usepackage{xcolor}

\begin{document}
\newcolumntype{Z}{S[round-mode=places,round-precision=1]}
\centering
\begin{tabu}{X[l]ZZZZ }
%\rowfont{\color{red}}
\toprule
{Farm Animal}&{Mean}&{S.d.}&{p50}\\
\midrule
Sheep & 40.96408 & 14.74988 & 17.0000 \\
Goats & 44.53074 & 12.77132 & 13.04183  \\  
Cows & 21.08170 & 23.65936 & 11.17796 \\        
Pigs & 37.43113 & 15.24949 & 61.66667 \\
%\rowfont{\color{blue}}
Donkeys & 10.84207 & 20.63621 & 10.66225 \\
Chicken & 14.28904 & 13.78381 & 23.99308 \\
%\rowfont{\color{green}}
Turkeys & 22.90579 & 22.32673 & 32.53234 \\
Horses & 24.93417 & 56.81986 & 12.96247 \\
Rabbits  & 32.15897 & 6.57493 & 12.17391 \\
Geese & 11.33306 & 5.74882 & 4.33333 \\
\bottomrule
\end{tabu}
\end{document}

I get the following output:enter image description here

However, I want to highlight certain rows using colours. It this that gives me strange results.

\documentclass[a4paper]{scrreprt}
\usepackage{siunitx,booktabs}
\usepackage{tabu}
\usepackage{graphicx}
\usepackage{xcolor}

\begin{document}
\newcolumntype{Z}{S[round-mode=places,round-precision=1]}
\centering
\begin{tabu}{X[l]ZZZZ }
\rowfont{\color{red}}
\toprule
{Farm Animal}&{Mean}&{S.d.}&{p50}\\
\midrule
Sheep & 40.96408 & 14.74988 & 17.0000 \\
Goats & 44.53074 & 12.77132 & 13.04183  \\  
Cows & 21.08170 & 23.65936 & 11.17796 \\        
Pigs & 37.43113 & 15.24949 & 61.66667 \\
\rowfont{\color{blue}}
Donkeys & 10.84207 & 20.63621 & 10.66225 \\
Chicken & 14.28904 & 13.78381 & 23.99308 \\
\rowfont{\color{green}}
Turkeys & 22.90579 & 22.32673 & 32.53234 \\
Horses & 24.93417 & 56.81986 & 12.96247 \\
Rabbits  & 32.15897 & 6.57493 & 12.17391 \\
Geese & 11.33306 & 5.74882 & 4.33333 \\
\bottomrule
\end{tabu}
\end{document}

Notice that now the Farm animal, Donkeys and Turkeys rows are misaligned after applying the colours. How can I have them coloured without the misalignments? thanks
enter image description here

1

You have to be more careful with color than fonts as to where you specify the change

\documentclass[a4paper]{scrreprt}
\usepackage{siunitx,booktabs}
\usepackage{tabu}
\usepackage{graphicx}
\usepackage{xcolor}

\begin{document}
\newcolumntype{Z}{S[round-mode=places,round-precision=1]}
\centering
\begin{tabu}{X[l]ZZZZ }
\rowfont{\leavevmode\color{red}}%
\toprule
{Farm Animal}&{Mean}&{S.d.}&{p50}\\
\midrule
Sheep & 40.96408 & 14.74988 & 17.0000 \\
Goats & 44.53074 & 12.77132 & 13.04183  \\  
Cows & 21.08170 & 23.65936 & 11.17796 \\        
Pigs & 37.43113 & 15.24949 & 61.66667 \\
\rowfont{\leavevmode\color{blue}}%
Donkeys & 10.84207 & 20.63621 & 10.66225 \\
Chicken & 14.28904 & 13.78381 & 23.99308 \\
\rowfont{\leavevmode\color{green}}%
Turkeys & 22.90579 & 22.32673 & 32.53234 \\
Horses & 24.93417 & 56.81986 & 12.96247 \\
Rabbits  & 32.15897 & 6.57493 & 12.17391 \\
Geese & 11.33306 & 5.74882 & 4.33333 \\
\bottomrule
\end{tabu}
\end{document}

enter image description here

See texdoc color (grfguide) the footnote on page 6....

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.