
Estou tentando aplicar cores alternadas ao meu documento, usando o pacote xcolor com a opção table. Pelo que sei é possível definir as cores alternadas no preâmbulo, para que sejam aplicadas a todas as tabelas seguintes.
Mas se eu usar dessa maneira, não obtenho cores de mesa idênticas. Onde estou errado com essa abordagem?
\documentclass{scrbook}
\usepackage[table]{xcolor}
\rowcolors{2}{gray}{white}
\begin{document}
\begin{table}[h]
\centering
\begin{tabular}{|ll|}
\hline
$1_1$ & $1_2$ \\
\hline
$2_1$ & $2_2$ \\
\hline
$3_1$ & $3_2$ \\
\hline
$4_1$ & $4_2$ \\
\hline
\end{tabular}
\end{table}
Text
\begin{table}[h]
\centering
\begin{tabular}{|ll|}
\hline
$1_1$ & $1_2$ \\
\hline
$2_1$ & $2_2$ \\
\hline
$3_1$ & $3_2$ \\
\hline
$4_1$ & $4_2$ \\
\hline
\end{tabular}
\end{table}
\end{document}
Responder1
Experimente isto:
\documentclass{scrbook}
\usepackage[table]{xcolor}
\rowcolors{2}{gray}{white}
\let\oldtabular\tabular
\def\tabular{\global\rownum=0\relax\oldtabular}
\begin{document}
\begin{table}[h]
\centering
\begin{tabular}{|ll|}
\hline
$1_1$ & $1_2$ \\
\hline
$2_1$ & $2_2$ \\
\hline
$3_1$ & $3_2$ \\
\hline
$4_1$ & $4_2$ \\
\hline
\end{tabular}
\end{table}
Text
\begin{table}[h]
\centering
\begin{tabular}{|ll|}
\hline
$1_1$ & $1_2$ \\
\hline
$2_1$ & $2_2$ \\
\hline
$3_1$ & $3_2$ \\
\hline
$4_1$ & $4_2$ \\
\hline
\end{tabular}
\end{table}
\end{document}