I am trying to create a table with alternating row colors using the xcolor
package with the [table]
option.
The following example demonstrates that the row coloring (uncommenting the \rowcolors..
) may hide/cover the table contents.
In particular there seems to be an issue with the @-expressions.
\documentclass{article}
\usepackage[table]{xcolor}
\usepackage{booktabs}
\begin{document}
\begin{table}
\footnotesize
\centering
%\rowcolors{2}{gray!15}{white}
\begin{tabular}{lr@{\hspace{.1em}}c@{\hspace{.1em}}lcc}
&&&& Col 1 & Col 2 \\ \toprule
Row 1 & $(100$ & $\times$ & $100)$ & $1$ & $2$ \\
Row 2 & $(100$ & $\times$ & $1000)$& $3$ & $4$ \\
\bottomrule
\end{tabular}
\end{table}
\end{document}
- How can we prevent that?
- A second question is whether there is an easy way to cover the entire line with color; one can observe the white padding in the gray line.
Best Answer
For the first question, you can remove the
\tabcolsep
separately for those two columns likeand for second, you can define a
\bottomrulec
likeand use it instead of
\bottomrule
. Here are the coloured versions for\toprule
and\midrule
in case if you need them.Your code modified: