未定义的控制序列 \rowcolors

未定义的控制序列 \rowcolors

出现交替行错误,提示未定义控制序列。请帮忙!

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

在此处输入图片描述

相关内容