[Tex/LaTex] A single row background colour

colortables

Below is my code. How do I add a background colour to the first row (only the first row, please)?

\begin{table}[!htb]
    \centering
    \begin{tabular}{c c c}
        \toprule
        \textbf{Temperature} [K] & \textbf{Thickness}$[\mu m]$ & \textbf{Permittivity}\\
        \midrule
        $H \# /k$ & K & 17762 \\
        \bottomrule
    \end{tabular}

Best Answer

You can't use booktabs with coloured rows as it introduces some vertical spaces around horizontal rules, which will not be coloured. Instead I suggest using \boldline, a small package from the shipunov bundle, which allows for hlines with variable thickness. The syntax is \hlineB{number} (or \clineB), which will draw a horizontal line with thickness equal to number × \arrayrulewidth.

To replace the vertical spacing added by booktabs, you can use the cellspace package, which can add some minimal vertical padding at the top and bottom of cells.

\documentclass[a4paper]{article}
\usepackage[table, x11names]{xcolor}
\usepackage{array, booktabs, boldline} %
\usepackage{cellspace}
\setlength\cellspacetoplimit{4pt}
\setlength\cellspacebottomlimit{4pt}
\begin{document}

\begin{table}[!htb]
    \centering
    \begin{tabular}{Sc c c}
        \hlineB{2}
\rowcolor{SeaGreen3!30!} \textbf{Temperature} [K] & \textbf{Thickness}$[\mu m]$ & \textbf{Permittivity}\\
        \hlineB{1.5}
        $H \# /k$ & K & 17762 \\
        \hlineB{2}
    \end{tabular}
\end{table}

\end{document} 

enter image description here