[Tex/LaTex] Undefined Control sequences \rowcolors

rowcolor

Getting errors with alternating rows saying undefined control sequences. Any help please!

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

Best Answer

You have to use \usepackage[table]{xcolor} instead of \usepackage{xcolor}. Second since you use tabularx, better use X column and get rid of \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}

enter image description here

Related Question