# A single row background colour

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}

• Welcome to TeX.SX! Please make your code compilable (if possible), or at least complete it with \documentclass{...}, the required \usepackage's, \begin{document}, and \end{document}. That may seem tedious to you, but think of the extra work it represents for TeX.SX users willing to give you a hand. Help them help you: remove that one hurdle between you and a solution to your problem. – Martin Schröder May 27 '15 at 23:34

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


Simpy use \hline instead of \toprule, \midrule, or \bootomrule. Or set the arrayrulewidth

\PassOptionsToPackage{table,x11names}{xcolor}%  only needed if you get an option clash
\documentclass[a4paper]{article}
\usepackage{xcolor}
\usepackage{booktabs}

\begin{document}
\def\arraystretch{1.5}% vertical stretch
\setlength\arrayrulewidth{1pt}% thicker line
\begin{tabular}{c c c}\hline
\rowcolor{SeaGreen3!30!}\global\setlength\arrayrulewidth{0.4pt}
\textbf{Temperature} [K] & \textbf{Thickness}$[\mu m]$ & \textbf{Permittivity}\\\hline\global\setlength\arrayrulewidth{1pt}
$H \# /k$ & K & 17762 \\\hline
\end{tabular}%
\setlength\arrayrulewidth{0.4pt}% set to old value

\end{document}


• I have these packages which clash with you package. Do you know where is the mistake? – Hisham Alghamdi May 27 '15 at 19:57
• \documentclass{ecsthesis} % Use the progress Style \graphicspath{{../Figures/}} % Location of your graphics files \hypersetup{colorlinks=true} % Set to false for black/white printing \input{Definitions} % Include your abbreviations \usepackage[sort]{cite} \usepackage{amsmath} \usepackage[framed,numbered,autolinebreaks,useliterate]{mcode} \usepackage{upquote} \usepackage{subfigure} \usepackage{multirow} \usepackage{xcolor,colortbl} \usepackage[most]{tcolorbox} – Hisham Alghamdi May 27 '15 at 19:57
• Option clash for package xcolor. \usepackage – Hisham Alghamdi May 27 '15 at 19:58
• Very probably, xcolor is loaded twice, with different options. Either you load it only once, with all the options, or, if xcolor is already loaded by a package, a simple workaround consists in adding table,x11names to the options of the document class, instead of loading xcolor twice. – Bernard May 27 '15 at 20:20
• Instead of loading the package use \PassOptionsToPackage{table,x11names}{xcolor}`. see edited answer – user2478 May 28 '15 at 4:15