I'd like to make a longtable with the first (head) row colored in grey.
Since booktabs inserts white space below the \toprule and above the \midrule, i need to insert a colored rule:
\newcommand*{\belowrulesepcolor}[1]{%
\noalign{%
\kern-\belowrulesep
\begingroup
\color{#1}%
\hrule height\belowrulesep
\endgroup
}%
}
\newcommand*{\aboverulesepcolor}[1]{%
\noalign{%
\begingroup
\color{#1}%
\hrule height\aboverulesep
\endgroup
\kern-\aboverulesep
}%
}
This works well within the tabular environment. But if I use the longtable environment, the \hrule is getting too long.
Here is my MWE with a picture of the output:
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[english]{babel}
\usepackage[T1]{fontenc}
\usepackage{geometry}
\geometry{paperwidth=5cm,paperheight=5cm} % small page
\pagestyle{empty}
\usepackage{booktabs, longtable}
\usepackage[table]{xcolor}
\newcommand*{\belowrulesepcolor}[1]{% fills the white space with a colored rule
\noalign{%
\kern-\belowrulesep
\begingroup
\color{#1}%
\hrule height\belowrulesep
\endgroup
}%
}
\newcommand*{\aboverulesepcolor}[1]{%
\noalign{%
\begingroup
\color{#1}%
\hrule height\aboverulesep
\endgroup
\kern-\aboverulesep
}%
}
\definecolor{headcolor}{gray}{0.8}
\begin{document}
\centering
\begin{longtable}{lll}
\toprule \belowrulesepcolor {headcolor}
\rowcolor{headcolor}
Col1 & Col2 \\ \aboverulesepcolor{headcolor} \midrule \endfirsthead
\toprule \belowrulesepcolor {headcolor}
\rowcolor{headcolor}
Col1 & Col2 \\ \aboverulesepcolor{headcolor} \midrule \endhead
\bottomrule
\endfoot
\bottomrule
\endlastfoot
A&B \\
A&B \\
A&B \\
A&B \\
A&B \\
A&B \\
A&B \\
A&B \\
A&B \\
A&B \\
A&B \\
A&B \\
\end{longtable}
\end{document}




One last thing: The default width of
– Dorian Feb 19 '16 at 12:35\topruleand\bottomruleinbooktabsis\heavyrulewidth. Hence i've edited the0.1emto\heavyrulewidth.