\hhline with || separation in coloured table

I want to create a table like the following. Using booktabs is unfortunately not an option. I need to colour the table header and want to show on which columns the \multicolumns are used. Therefore I use \hhline with || to introduce a small break in the lines. But the space between the two lines is white and not coloured.

\documentclass[]{article}

\usepackage[table]{xcolor}
\usepackage{hhline}

\begin{document}
\begin{tabular}[]{ccccc}
\hline
\rowcolor{gray}\multicolumn{3}{c}{Foo} & \multicolumn{2}{c}{Bar}\\
\hhline{---||--}
\rowcolor{gray}foo & bar & baz & bang & bang\\
\hline
foo & bar & baz & bang & bang\\
foo & bar & baz & bang & bang\\
foo & bar & baz & bang & bang\\
\hline
\end{tabular}
\end{document}


A solution doesn't have to use hhline but should look just like \cline.

• you can colour the lines and the spaces between using hhline as redefined by colortbl, see the richard of york example in the colortbl doc – David Carlisle Feb 7 '18 at 14:23

You can obtain what you want with a supplementary empty column and using the possibility for an \hhline to have segments with different colours. Here is a code, in which I took the liberty to replace the gray colour by a lighter shade of grey, making the contents of the coloured cells more readable:

\documentclass[]{article}

\usepackage[table, svgnames]{xcolor}
\usepackage{hhline}

\begin{document}

\begin{tabular}[]{ccc!{\hspace*{-2pt}}c!{\hspace*{-2pt}}cc}
\hline
\rowcolor{WhiteSmoke}\multicolumn{3}{c}{Foo}& & \multicolumn{2}{c}{Bar}\\%
\hhline{--->{\arrayrulecolor{WhiteSmoke}}->{\arrayrulecolor{black}}--}
\rowcolor{WhiteSmoke}foo & bar & baz & & bang & bang \\
\hline
foo & bar & baz & & bang & bang\\
foo & bar & baz & & bang & bang\\
foo & bar & baz & & bang & bang\\
\hline
\end{tabular}

\end{document}


• Thank you for the answer. The empty column is an option I'd like to avoid, but gives good results. I personally am satisfied by my own solution though. Nonetheless you get an upvote :) And the changed colour is no problem -- as you can see in my own answer, I didn't use a dark grey as well, it was just to minimize the MWE. – Skillmon Feb 7 '18 at 18:50

I came up with a better (imho) looking solution than the \hhline approach which inserts the correct color in the space between the \clines. The definition of \@mycline matches the one of \@cline just with the additional \rules added.

\documentclass[border=2mm]{article}

\usepackage[table]{xcolor}
\usepackage{array}
\usepackage{hhline}

\definecolor{tablegray}{gray}{0.85}

\makeatletter
\newcommand*\myclineColor[1]{\colorlet{mycline@color}{#1}}
\myclineColor{tablegray}
\newcommand*\mycline[1]{\@mycline#1\@nil}
\def\@mycline#1-#2\@nil
{%
\omit
\@multicnt#1%
\ifnum\@multicnt=\@ne
\@firstofone{&\omit}%
\fi
\@multicnt#2%
{\color{mycline@color}\rule{0.5\tabcolsep}\arrayrulewidth}% inserted
{\color{mycline@color}\rule{0.5\tabcolsep}\arrayrulewidth}% inserted
\cr\noalign{\vskip-\arrayrulewidth}%
}
\makeatother

\begin{document}
\begin{tabular}[]{ccccc}
\hline
\rowcolor{tablegray}\multicolumn{3}{c}{Foo} & \multicolumn{2}{c}{Bar}\\
\mycline{1-3}\mycline{4-5}\noalign{\vskip\arrayrulewidth}
\rowcolor{tablegray}foo & bar & baz & bang & bang\\
\hline
foo & bar & baz & bang & bang\\
foo & bar & baz & bang & bang\\
foo & bar & baz & bang & bang\\
\hline
\end{tabular}\medskip
\end{document}