![未定义的控制序列 \rowcolors](https://linux22.com/image/306563/%E6%9C%AA%E5%AE%9A%E4%B9%89%E7%9A%84%E6%8E%A7%E5%88%B6%E5%BA%8F%E5%88%97%20%5Crowcolors.png)
出现交替行错误,提示未定义控制序列。请帮忙!
\documentclass{article}
\usepackage{xcolor}
\usepackage{booktabs}
\usepackage{graphicx}
\begin{document}
\begin{table}
\captionsetup{font={footnotesize}}
\caption{List of localities}
\label{table2}
\scriptsize
\centering
\rowcolors[]{1}{white}{cyan}
\begin{threeparttable}
\begin{tabularx}{\textwidth}{@{\extracolsep{\fill}}l c |l c | l c}
\specialrule{.2em}{.1em}{.1em}
%\textbf{Locality} &
%\multicolumn{3}{c}{\textbf{Countries}\tnote{\textasteriskcentered}} \\
%\cmidrule(lr){1-3}
\textbf{G} & \textbf{Population size} & \textbf{L} & \textbf{Population size} & \textbf{SL} & \textbf{Population size} \\
\specialrule{.2em}{.1em}{.1em}
Upper Guinea & $4,308,494$ & Northern & $2,233,091$ & & $4,976,871$ \\
Middle Guinea & $2,670,567$ & Southern & $1,243,517$ & & \\
Lower Guinea & $3,649,911$ & & & & \\
\specialrule{.2em}{.1em}{.1em}
Total & $10,628,972$ & & $3,476,608$ & & $4,976,871$ \\
\specialrule{.2em}{.1em}{.1em}
\end{tabularx}
\begin{tablenotes}[para]
\tiny
\item[\textdagger]
\tiny Data.
\end{tablenotes}
\end{threeparttable}
\end{table}
\end{document}
答案1
您必须使用\usepackage[table]{xcolor}
而不是\usepackage{xcolor}
。其次,既然您使用tabularx
,最好使用X
列 并去掉\extracolsep
。
\documentclass{article}
\usepackage[table]{xcolor}
\usepackage{booktabs}
\usepackage{graphicx}
\usepackage{caption}
\usepackage{threeparttable}
\usepackage{tabularx}
\begin{document}
\begin{table}[htb]
\captionsetup{font=footnotesize}
\caption{List of localities}
\label{table2}
\scriptsize
\centering
\rowcolors[]{1}{white}{cyan}
\begin{threeparttable}
\begin{tabularx}{\textwidth}{X c |X c | X c}
\specialrule{.2em}{.1em}{.1em}
%\textbf{Locality} &
%\multicolumn{3}{c}{\textbf{Countries}\tnote{\textasteriskcentered}} \\
%\cmidrule(lr){1-3}
\textbf{G} & \textbf{Population size} & \textbf{L} & \textbf{Population size} & \textbf{S
L} & \textbf{Population size} \\
\specialrule{.2em}{.1em}{.1em}
Upper Guinea & $4,308,494$ & Northern & $2,233,091$ & & $4,976,871$ \\
Middle Guinea & $2,670,567$ & Southern & $1,243,517$ & & \\
Lower Guinea & $3,649,911$ & & & & \\
\specialrule{.2em}{.1em}{.1em}
Total & $10,628,972$ & & $3,476,608$ & & $4,976,871$ \\
\specialrule{.2em}{.1em}{.1em}
\end{tabularx}
\begin{tablenotes}[para]
\tiny
\item[\textdagger]
\tiny Data.
\end{tablenotes}
\end{threeparttable}
\end{table}
\end{document}