
我正在嘗試使用 xcolor 套件和 table 選項將交替顏色應用於我的文件。據我所知,可以在序言中定義交替顏色,因此它們適用於以下所有表格。
但如果我這樣使用它,我就不會得到相同的桌面顏色。我這個方法哪裡錯了?
\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}
答案1
嘗試這個:
\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}