[Tex/LaTex] vertical space around horizontal rules between tabu rows while maintaining color

colorspacingtabu

I would like to increase the vertical space before and after a horizontal rule in a tabu table but want the color that is in the cells below and above the rule to not be broken but continue right throuh the rule.

Here is my attempt. The first horizontal rule (which is green) does not have enough vertical space so I tried a couple of approaches shown in the red and blue horizontal rules but in both those cases I get white space intervening and I want the color to go right through from the cell above to the cell below. In addition the red rule does not really have enough space above and below it anyways. ADDED: The vertical spacing between rows 1 and 2 should not be changed since there is no rule between them. Also it might be that different horizontal rules require different vertical spacing so the spacing should ideally be controllable on a rule by rule basis.

\documentclass{article}
\usepackage{xcolor}
\usepackage{colortbl}
\usepackage{booktabs}
\usepackage{tabu}
\begin{document}

\begin{center}
\begin{tabu}{X>{\columncolor{blue}}XXX}
1 & 2 & a & b\\
1 & 2 & a & b\\
\tabucline[green]-
1 & 2 & a & b\\
\arrayrulecolor{red}
\cmidrule(r{1.0ex}){1-2}\cmidrule(l{1.0ex}){3-4}
1 & 2 & \cellcolor{green}a & b\\
\addlinespace
\tabucline[blue]-
\addlinespace
1 & 2 & \cellcolor{green}a & b\\
\end{tabu}
\end{center}
\end{document}

Output:

screenshot

Best Answer

Is it what you want ?

\documentclass{article}
\usepackage{xcolor}
\usepackage{colortbl}
\usepackage{booktabs}
\usepackage{adjustbox}
\usepackage{tabu}
\begin{document}
\belowrulesep=0pt
\aboverulesep=0pt

\begin{center}
\begin{tabu}{X>{\columncolor{blue}}XXX}
1 & 2 & a & b\\
1 & 2 & a & b\\
\tabucline[green]-
1 & 2 & a & b\\
\arrayrulecolor{red}
\cmidrule(r{2.0ex}){1-2}\cmidrule(l{2.0ex}){3-4}
\adjustbox{margin=0pt 10pt 0pt 0pt}{1} & 2 & \cellcolor{green}a & b\\
\tabucline[blue]-
\adjustbox{margin=0pt 0pt 0pt 10pt}{1} & 2 & \cellcolor{green}a & b\\
\end{tabu}
\end{center}
\end{document}

This is more a hack than a real solution. I add margin inside the cells with adjustbox, and remove the space around cmidrule ....