Combining longtable, booktabs, and xcolor in LaTex, layout problems

2.2k views Asked by At

I am trying to create a nice-looking table over multiple pages in LaTeX. For that, I am using longtable to divide the table in different pages of the document, booktabs to give it a nicer look, and xcolor to change the way the table looks.

It's a 3-columns table. I would like the header to be shaded in grey, and the rows to have alternating white/myblue shades.

The booktabs and xcolor layout worked nicely when I used \begin{table} combined with \begin{tabular} packages. However, since the table is too long for a single page, I changed to longtable. Now, neither booktabs options (\toprule, etc) nor xcolor (\rowcolors) work. Strangely, \rowcolor for the header now works. Since \toprule and \midrule from booktabs were not working, I regressed to using \hline.

The code I have right now is the following:

\documentclass{article}
\usepackage[utf8]{inputenc}

\usepackage[table]{xcolor}
\usepackage{longtable}
\usepackage{booktabs}
\definecolor{myblue}{RGB}{0,204,204}

\begin{document}


\begin{small}
\begin{longtable}{llc}
\caption{Primer list for IRD-associated loci long-range PCRs}
\label{tab:ch3_1_LR_primers}
\rowcolors{1}{white}{myblue!15}
\hline



\rowcolor{gray!20}
\textbf{Text 1} & \textbf{Text sequence} & \textbf{Number}\\
\hline
\endfirsthead

\caption{continued from previous page} \\

\endhead


\endlastfoot

ABC\_01\_A & AAAAAAAAAAAAAAAAAAAAAAAAAAAA & 67.01\\
ABC\_01\_B & BBBBBBBBBBBBBBBBBBBBBBBBBBBB & 66.87\\
ABC\_02\_A & AAAAAAAAAAAAAAAAAAAAAAAAAAAA & 67.23\\
ABC\_02\_B & BBBBBBBBBBBBBBBBBBBBBBBBBBBB & 66.91\\
ABC\_03\_A & AAAAAAAAAAAAAAAAAAAAAAAAAAAA & 66.98\\
ABC\_03\_B & BBBBBBBBBBBBBBBBBBBBBBBBBBBB & 67.05\\
ABC\_01\_A & AAAAAAAAAAAAAAAAAAAAAAAAAAAA & 67.01\\
ABC\_01\_B & BBBBBBBBBBBBBBBBBBBBBBBBBBBB & 66.87\\
ABC\_02\_A & AAAAAAAAAAAAAAAAAAAAAAAAAAAA & 67.23\\
ABC\_02\_B & BBBBBBBBBBBBBBBBBBBBBBBBBBBB & 66.91\\
ABC\_03\_A & AAAAAAAAAAAAAAAAAAAAAAAAAAAA & 66.98\\
ABC\_03\_B & BBBBBBBBBBBBBBBBBBBBBBBBBBBB & 67.05\\
ABC\_01\_A & AAAAAAAAAAAAAAAAAAAAAAAAAAAA & 67.01\\
ABC\_01\_B & BBBBBBBBBBBBBBBBBBBBBBBBBBBB & 66.87\\
ABC\_02\_A & AAAAAAAAAAAAAAAAAAAAAAAAAAAA & 67.23\\
ABC\_02\_B & BBBBBBBBBBBBBBBBBBBBBBBBBBBB & 66.91\\
ABC\_03\_A & AAAAAAAAAAAAAAAAAAAAAAAAAAAA & 66.98\\
ABC\_03\_B & BBBBBBBBBBBBBBBBBBBBBBBBBBBB & 67.05\\
ABC\_01\_A & AAAAAAAAAAAAAAAAAAAAAAAAAAAA & 67.01\\
ABC\_01\_B & BBBBBBBBBBBBBBBBBBBBBBBBBBBB & 66.87\\
ABC\_02\_A & AAAAAAAAAAAAAAAAAAAAAAAAAAAA & 67.23\\
ABC\_02\_B & BBBBBBBBBBBBBBBBBBBBBBBBBBBB & 66.91\\
ABC\_03\_A & AAAAAAAAAAAAAAAAAAAAAAAAAAAA & 66.98\\
ABC\_03\_B & BBBBBBBBBBBBBBBBBBBBBBBBBBBB & 67.05\\
ABC\_01\_A & AAAAAAAAAAAAAAAAAAAAAAAAAAAA & 67.01\\
ABC\_01\_B & BBBBBBBBBBBBBBBBBBBBBBBBBBBB & 66.87\\
ABC\_02\_A & AAAAAAAAAAAAAAAAAAAAAAAAAAAA & 67.23\\
ABC\_02\_B & BBBBBBBBBBBBBBBBBBBBBBBBBBBB & 66.91\\
ABC\_03\_A & AAAAAAAAAAAAAAAAAAAAAAAAAAAA & 66.98\\
ABC\_03\_B & BBBBBBBBBBBBBBBBBBBBBBBBBBBB & 67.05\\
ABC\_01\_A & AAAAAAAAAAAAAAAAAAAAAAAAAAAA & 67.01\\
ABC\_01\_B & BBBBBBBBBBBBBBBBBBBBBBBBBBBB & 66.87\\
ABC\_02\_A & AAAAAAAAAAAAAAAAAAAAAAAAAAAA & 67.23\\
ABC\_02\_B & BBBBBBBBBBBBBBBBBBBBBBBBBBBB & 66.91\\
ABC\_03\_A & AAAAAAAAAAAAAAAAAAAAAAAAAAAA & 66.98\\
ABC\_03\_B & BBBBBBBBBBBBBBBBBBBBBBBBBBBB & 67.05\\
ABC\_01\_A & AAAAAAAAAAAAAAAAAAAAAAAAAAAA & 67.01\\
ABC\_01\_B & BBBBBBBBBBBBBBBBBBBBBBBBBBBB & 66.87\\
ABC\_02\_A & AAAAAAAAAAAAAAAAAAAAAAAAAAAA & 67.23\\
ABC\_02\_B & BBBBBBBBBBBBBBBBBBBBBBBBBBBB & 66.91\\
ABC\_03\_A & AAAAAAAAAAAAAAAAAAAAAAAAAAAA & 66.98\\
ABC\_03\_B & BBBBBBBBBBBBBBBBBBBBBBBBBBBB & 67.05\\
ABC\_01\_A & AAAAAAAAAAAAAAAAAAAAAAAAAAAA & 67.01\\
ABC\_01\_B & BBBBBBBBBBBBBBBBBBBBBBBBBBBB & 66.87\\
ABC\_02\_A & AAAAAAAAAAAAAAAAAAAAAAAAAAAA & 67.23\\
ABC\_02\_B & BBBBBBBBBBBBBBBBBBBBBBBBBBBB & 66.91\\
ABC\_03\_A & AAAAAAAAAAAAAAAAAAAAAAAAAAAA & 66.98\\
ABC\_03\_B & BBBBBBBBBBBBBBBBBBBBBBBBBBBB & 67.05\\
ABC\_01\_A & AAAAAAAAAAAAAAAAAAAAAAAAAAAA & 67.01\\
ABC\_01\_B & BBBBBBBBBBBBBBBBBBBBBBBBBBBB & 66.87\\
ABC\_02\_A & AAAAAAAAAAAAAAAAAAAAAAAAAAAA & 67.23\\
ABC\_02\_B & BBBBBBBBBBBBBBBBBBBBBBBBBBBB & 66.91\\
ABC\_03\_A & AAAAAAAAAAAAAAAAAAAAAAAAAAAA & 66.98\\
ABC\_03\_B & BBBBBBBBBBBBBBBBBBBBBBBBBBBB & 67.05\\
ABC\_01\_A & AAAAAAAAAAAAAAAAAAAAAAAAAAAA & 67.01\\
ABC\_01\_B & BBBBBBBBBBBBBBBBBBBBBBBBBBBB & 66.87\\
ABC\_02\_A & AAAAAAAAAAAAAAAAAAAAAAAAAAAA & 67.23\\
ABC\_02\_B & BBBBBBBBBBBBBBBBBBBBBBBBBBBB & 66.91\\
ABC\_03\_A & AAAAAAAAAAAAAAAAAAAAAAAAAAAA & 66.98\\
ABC\_03\_B & BBBBBBBBBBBBBBBBBBBBBBBBBBBB & 67.05\\

\end{longtable}
\end{small}
\end{document}

What do I need to change to have commands from both packages to work?

Any help is very much appreciated.

1

There are 1 answers

0
samcarter_is_at_topanswers.xyz On BEST ANSWER

With a couple of missing \\, misplaced \rowcolours and removing the unnecessary \endlastfoot one can make the code compilable. In theory you could now also replace the \hline with \toprule etc, but then you will face the problem that booktabs together with such zebra stripe tables will lead to white gaps, so you have to decide

  • either use such zebra stripes together with \hline

or

  • make a nice looking table with the booktab rules and abandon the colouring

(I strongly suggest the second approach)

\documentclass{article}
\usepackage[utf8]{inputenc}

\usepackage[table]{xcolor}
\usepackage{longtable}
\usepackage{booktabs}
\definecolor{myblue}{RGB}{0,204,204}

\begin{document}

{
\small
\rowcolors{1}{white}{myblue!15}
\begin{longtable}{llc}
\caption{Primer list for IRD-associated loci long-range PCRs}
\label{tab:ch3_1_LR_primers}\\
\hline
\rowcolor{gray!20}\textbf{Text 1} & \textbf{Text sequence} & \textbf{Number}\\
\hline
\endfirsthead
\caption{continued from previous page} \\
\endhead
ABC\_01\_A & AAAAAAAAAAAAAAAAAAAAAAAAAAAA & 67.01\\
ABC\_01\_B & BBBBBBBBBBBBBBBBBBBBBBBBBBBB & 66.87\\
ABC\_02\_A & AAAAAAAAAAAAAAAAAAAAAAAAAAAA & 67.23\\
ABC\_02\_B & BBBBBBBBBBBBBBBBBBBBBBBBBBBB & 66.91\\
ABC\_03\_A & AAAAAAAAAAAAAAAAAAAAAAAAAAAA & 66.98\\
ABC\_03\_B & BBBBBBBBBBBBBBBBBBBBBBBBBBBB & 67.05\\
ABC\_01\_A & AAAAAAAAAAAAAAAAAAAAAAAAAAAA & 67.01\\
ABC\_01\_B & BBBBBBBBBBBBBBBBBBBBBBBBBBBB & 66.87\\
ABC\_02\_A & AAAAAAAAAAAAAAAAAAAAAAAAAAAA & 67.23\\
ABC\_02\_B & BBBBBBBBBBBBBBBBBBBBBBBBBBBB & 66.91\\
ABC\_03\_A & AAAAAAAAAAAAAAAAAAAAAAAAAAAA & 66.98\\
ABC\_03\_B & BBBBBBBBBBBBBBBBBBBBBBBBBBBB & 67.05\\
ABC\_01\_A & AAAAAAAAAAAAAAAAAAAAAAAAAAAA & 67.01\\
ABC\_01\_B & BBBBBBBBBBBBBBBBBBBBBBBBBBBB & 66.87\\
ABC\_02\_A & AAAAAAAAAAAAAAAAAAAAAAAAAAAA & 67.23\\
ABC\_02\_B & BBBBBBBBBBBBBBBBBBBBBBBBBBBB & 66.91\\
ABC\_03\_A & AAAAAAAAAAAAAAAAAAAAAAAAAAAA & 66.98\\
ABC\_03\_B & BBBBBBBBBBBBBBBBBBBBBBBBBBBB & 67.05\\
ABC\_01\_A & AAAAAAAAAAAAAAAAAAAAAAAAAAAA & 67.01\\
ABC\_01\_B & BBBBBBBBBBBBBBBBBBBBBBBBBBBB & 66.87\\
ABC\_02\_A & AAAAAAAAAAAAAAAAAAAAAAAAAAAA & 67.23\\
ABC\_02\_B & BBBBBBBBBBBBBBBBBBBBBBBBBBBB & 66.91\\
ABC\_03\_A & AAAAAAAAAAAAAAAAAAAAAAAAAAAA & 66.98\\
ABC\_03\_B & BBBBBBBBBBBBBBBBBBBBBBBBBBBB & 67.05\\
ABC\_01\_A & AAAAAAAAAAAAAAAAAAAAAAAAAAAA & 67.01\\
ABC\_01\_B & BBBBBBBBBBBBBBBBBBBBBBBBBBBB & 66.87\\
ABC\_02\_A & AAAAAAAAAAAAAAAAAAAAAAAAAAAA & 67.23\\
ABC\_02\_B & BBBBBBBBBBBBBBBBBBBBBBBBBBBB & 66.91\\
ABC\_03\_A & AAAAAAAAAAAAAAAAAAAAAAAAAAAA & 66.98\\
ABC\_03\_B & BBBBBBBBBBBBBBBBBBBBBBBBBBBB & 67.05\\
ABC\_01\_A & AAAAAAAAAAAAAAAAAAAAAAAAAAAA & 67.01\\
ABC\_01\_B & BBBBBBBBBBBBBBBBBBBBBBBBBBBB & 66.87\\
ABC\_02\_A & AAAAAAAAAAAAAAAAAAAAAAAAAAAA & 67.23\\
ABC\_02\_B & BBBBBBBBBBBBBBBBBBBBBBBBBBBB & 66.91\\
ABC\_03\_A & AAAAAAAAAAAAAAAAAAAAAAAAAAAA & 66.98\\
ABC\_03\_B & BBBBBBBBBBBBBBBBBBBBBBBBBBBB & 67.05\\
ABC\_01\_A & AAAAAAAAAAAAAAAAAAAAAAAAAAAA & 67.01\\
ABC\_01\_B & BBBBBBBBBBBBBBBBBBBBBBBBBBBB & 66.87\\
ABC\_02\_A & AAAAAAAAAAAAAAAAAAAAAAAAAAAA & 67.23\\
ABC\_02\_B & BBBBBBBBBBBBBBBBBBBBBBBBBBBB & 66.91\\
ABC\_03\_A & AAAAAAAAAAAAAAAAAAAAAAAAAAAA & 66.98\\
ABC\_03\_B & BBBBBBBBBBBBBBBBBBBBBBBBBBBB & 67.05\\
ABC\_01\_A & AAAAAAAAAAAAAAAAAAAAAAAAAAAA & 67.01\\
ABC\_01\_B & BBBBBBBBBBBBBBBBBBBBBBBBBBBB & 66.87\\
ABC\_02\_A & AAAAAAAAAAAAAAAAAAAAAAAAAAAA & 67.23\\
ABC\_02\_B & BBBBBBBBBBBBBBBBBBBBBBBBBBBB & 66.91\\
ABC\_03\_A & AAAAAAAAAAAAAAAAAAAAAAAAAAAA & 66.98\\
ABC\_03\_B & BBBBBBBBBBBBBBBBBBBBBBBBBBBB & 67.05\\
ABC\_01\_A & AAAAAAAAAAAAAAAAAAAAAAAAAAAA & 67.01\\
ABC\_01\_B & BBBBBBBBBBBBBBBBBBBBBBBBBBBB & 66.87\\
ABC\_02\_A & AAAAAAAAAAAAAAAAAAAAAAAAAAAA & 67.23\\
ABC\_02\_B & BBBBBBBBBBBBBBBBBBBBBBBBBBBB & 66.91\\
ABC\_03\_A & AAAAAAAAAAAAAAAAAAAAAAAAAAAA & 66.98\\
ABC\_03\_B & BBBBBBBBBBBBBBBBBBBBBBBBBBBB & 67.05\\
ABC\_01\_A & AAAAAAAAAAAAAAAAAAAAAAAAAAAA & 67.01\\
ABC\_01\_B & BBBBBBBBBBBBBBBBBBBBBBBBBBBB & 66.87\\
ABC\_02\_A & AAAAAAAAAAAAAAAAAAAAAAAAAAAA & 67.23\\
ABC\_02\_B & BBBBBBBBBBBBBBBBBBBBBBBBBBBB & 66.91\\
ABC\_03\_A & AAAAAAAAAAAAAAAAAAAAAAAAAAAA & 66.98\\
ABC\_03\_B & BBBBBBBBBBBBBBBBBBBBBBBBBBBB & 67.05\\

\end{longtable}
}
\end{document}