表格行的对齐方式

表格行的对齐方式

下面是我的表格示例,我不明白它为什么会这样。在应用之前行颜色一切正常。

\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}

我得到以下输出:在此处输入图片描述

但是,我想使用颜色突出显示某些行。这给了我奇怪的结果。

\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}

请注意,现在农场动物、驴子和火鸡的行在应用颜色后错位了。我怎样才能让它们着色而不出现错位?谢谢
在此处输入图片描述

答案1

在指定更改的位置时,你必须对颜色比字体更加小心

\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}

在此处输入图片描述

请参阅texdoc color(grfguide)第 6 页的脚注......

相关内容