[Tex/LaTex] \hhline overlay \vline in coloured tabular

cellcolorcolorformattinghhlinetables

I'm creating a table containing HTML colour and merged cells. However, some \cline/\hline have not the default \arrayrulewidth.
I tried to use \setlength{\arrayrulewidth}{1pt} before \cline/\hline but failed.

\documentclass{article}
\usepackage{colortbl}
\usepackage{multirow}
\usepackage[table,xcdraw]{xcolor}
\usepackage{graphicx}
\begin{document}
\begin{table}
\centering
\resizebox{\columnwidth}{!}{
\begin{tabular}{|c|c|c|c|l|}
\hline
                            & 1                                              & 2           & 3       & 4                                     \\\hline  
\cellcolor[HTML]{FFE2CC} A  & B                                              & C           & D       & \multicolumn{1}{c|}{\cellcolor[HTML]{FFF2CC}E} \\\hline  
\cellcolor[HTML]{CDDAED}    & \multicolumn{3}{c|}{\cellcolor[HTML]{DAE8FC}F} & \multicolumn{1}{c|}{\cellcolor[HTML]{DAE8FC}}    \\\cline{2-4}  
\cellcolor[HTML]{CDDAED}    & \multicolumn{3}{c|}{\cellcolor[HTML]{DAE8FC}G} & \multicolumn{1}{c|}{\cellcolor[HTML]{DAE8FC}}    \\\cline{2-4}  
\cellcolor[HTML]{CDDAED}    & \multicolumn{3}{c|}{\cellcolor[HTML]{DAE8FC}H} & \cellcolor[HTML]{DAE8FC}   \\\cline{2-4}  
\cellcolor[HTML]{CDDAED}    & \cellcolor[HTML]{DAE8FC}I                      & \cellcolor[HTML]{DAE8FC}  &\cellcolor[HTML]{DAE8FC}J &   \cellcolor[HTML]{DAE8FC}    \\\cline{2-2} \cline{4-4} 
\cellcolor[HTML]{CDDAED}    & \cellcolor[HTML]{DAE8FC}                       & \cellcolor[HTML]{DAE8FC}  &\cellcolor[HTML]{DAE8FC}K &   \cellcolor[HTML]{DAE8FC}     \\\cline{4-4}  
\multirow{-6}{*}{\cellcolor[HTML]{CDDAED}J} & \multirow{-2}{*}{\cellcolor[HTML]{DAE8FC}}    & \multirow{-3}{*}{\cellcolor[HTML]{DAE8FC}}    &\cellcolor[HTML]{DAE8FC}L        &   \cellcolor[HTML]{DAE8FC}          \\\cline{1-4}  
\cellcolor[HTML]{D4B1E5}                               & \cellcolor[HTML]{E1D5E7}N                                    & \cellcolor[HTML]{E1D5E7}O                        &\cellcolor[HTML]{E1D5E7}N         &  \cellcolor[HTML]{E1D5E7}  \\\cline{2-4}  
\multirow{-2}{*}{\cellcolor[HTML]{D4B1E5}E}    & \multicolumn{1}{l|}{\cellcolor[HTML]{E1D5E7}} & \multicolumn{1}{l|}{\cellcolor[HTML]{E1D5E7}} &\cellcolor[HTML]{E1D5E7}Z       &  \cellcolor[HTML]{E1D5E7}     \\\cline{1-5}
\end{tabular}}
\caption{With color}
\end{table}
\end{document}

Table with color

I followed Werner's answer which use \hhline, but the white rule is more emphasized in coloured cells.

\begin{table}
\centering
\resizebox{\columnwidth}{!}{
\begin{tabular}{|c|c|c|c|l|}
\hline
                            & 1                                              & 2           & 3       & 4                                     \\\hline  
\cellcolor[HTML]{FFE2CC} A  & B                                              & C           & D       & \multicolumn{1}{c|}{\cellcolor[HTML]{FFF2CC}E} \\\hline  
\cellcolor[HTML]{CDDAED}    & \multicolumn{3}{c|}{\cellcolor[HTML]{DAE8FC}F} & \multicolumn{1}{c|}{\cellcolor[HTML]{DAE8FC}}    \\\hhline{|~|-|-|-|~|}  
\cellcolor[HTML]{CDDAED}    & \multicolumn{3}{c|}{\cellcolor[HTML]{DAE8FC}G} & \multicolumn{1}{c|}{\cellcolor[HTML]{DAE8FC}}    \\\hhline{|~|-|-|-|~|}  
\cellcolor[HTML]{CDDAED}    & \multicolumn{3}{c|}{\cellcolor[HTML]{DAE8FC}H} & \cellcolor[HTML]{DAE8FC}   \\\hhline{|~|-|-|-|~|}  
\cellcolor[HTML]{CDDAED}    & \cellcolor[HTML]{DAE8FC}I                      & \cellcolor[HTML]{DAE8FC}  &\cellcolor[HTML]{DAE8FC}J &   \cellcolor[HTML]{DAE8FC}    \\\hhline{|~|-|~|-|~|}
\cellcolor[HTML]{CDDAED}    & \cellcolor[HTML]{DAE8FC}                       & \cellcolor[HTML]{DAE8FC}  &\cellcolor[HTML]{DAE8FC}K &   \cellcolor[HTML]{DAE8FC}     \\\hhline{|~|~|~|-|~|}
\multirow{-6}{*}{\cellcolor[HTML]{CDDAED}J} & \multirow{-2}{*}{\cellcolor[HTML]{DAE8FC}}    & \multirow{-3}{*}{\cellcolor[HTML]{DAE8FC}}    &\cellcolor[HTML]{DAE8FC}L        &   \cellcolor[HTML]{DAE8FC}          \\\hhline{|-|-|-|-|~|}
\cellcolor[HTML]{D4B1E5}                               & \cellcolor[HTML]{E1D5E7}N                                    & \cellcolor[HTML]{E1D5E7}O                        &\cellcolor[HTML]{E1D5E7}N         &  \cellcolor[HTML]{E1D5E7}  \\\hhline{|~|-|-|-|~|}  
\multirow{-2}{*}{\cellcolor[HTML]{D4B1E5}E}    & \multicolumn{1}{l|}{\cellcolor[HTML]{E1D5E7}} & \multicolumn{1}{l|}{\cellcolor[HTML]{E1D5E7}} &\cellcolor[HTML]{E1D5E7}Z       &  \cellcolor[HTML]{E1D5E7}     \\\hline
\end{tabular}}
\caption{Using \texttt{hhline}}
\end{table}

Using \hhline

I then found Zarko's answer which consist of colour \hhline

\definecolor{M1}{HTML}{CDDAED}
\definecolor{M2}{HTML}{DAE8FC}

\begin{table}
\centering
\resizebox{\columnwidth}{!}{
\begin{tabular}{!{\color{black}\vrule}c!{\color{black}\vrule}c!{\color{black}\vrule}c!{\color{black}\vrule}c!{\color{black}\vrule}l!{\color{black}\vrule}}
\hline
                                            & 1                                              & 2                                                    & 3                              & 4                                     \\\hline  
\cellcolor[HTML]{FFE2CC} A                  & B                                              & C                                                    & D                              & \multicolumn{1}{c|}{\cellcolor[HTML]{FFF2CC}E} \\\hline  
\cellcolor[HTML]{CDDAED}                    & \multicolumn{3}{c|}{\cellcolor[HTML]{DAE8FC}F} & \multicolumn{1}{c|}{\cellcolor[HTML]{DAE8FC}}                                                                   \\\hhline{|>{\arrayrulecolor{M1}}-|>{\arrayrulecolor{M2}}-|>{\arrayrulecolor{M2}}-|>{\arrayrulecolor{M2}}-|>{\arrayrulecolor{M2}}-|>{\arrayrulecolor{black}}} 
\cellcolor[HTML]{CDDAED}                    & \multicolumn{3}{c|}{\cellcolor[HTML]{DAE8FC}G} & \multicolumn{1}{c|}{\cellcolor[HTML]{DAE8FC}}                                                                   \\\hhline{|>{\arrayrulecolor{M1}}-|>{\arrayrulecolor{M2}}-|>{\arrayrulecolor{M2}}-|>{\arrayrulecolor{M2}}-|>{\arrayrulecolor{M2}}-|>{\arrayrulecolor{black}}}
\end{tabular}}
\end{table}

The code above gives me this :

hhline coloured

but it's quite complicated and the intersections of \hhline and \vline are not in black. This issue can be solved if we could draw vline after \hhline. Is there a more elegant way to deal with such problem? Changing rule's colour is annoying.

Best Answer

I am a fan of packages that include others with improvements, in this case through the tabu package, you can vary the thickness and style of the horizontal lines with a single command \tabulinestyle{2pt black} but it will occur that spaces will appear, for that reason you must manually subtract the thickness at the end of new row command & foo \\[-barpt], where bar is the thickness of the line and do not forget to declare \setlength{\arrayrulewidth}{2pt} for the \cline command also with the same desired thicknness, for example in the code if I change the \tabulinestyle{3pt black} and I do not change the value in & foo \\[-2pt] I get this error:

enter image description here

In the MWE, is defined on 2pt \tabulinestyle{2pt black} and all the new row commands are substracted using & foo \\[-2pt]and I get this: enter image description here

The code is based on easy to read structure:

% arara: pdflatex: {synctex: yes, action: nonstopmode}
\documentclass{article}
\usepackage{tabu,booktabs}
\usepackage{tabularx}
\usepackage{multirow}
\usepackage[table,xcdraw]{xcolor}
\usepackage{graphicx}
% to not write all of these many times...
\definecolor{C1}{HTML}{FFE2CC}
\definecolor{C2}{HTML}{FFF2CC}
\definecolor{C3}{HTML}{DAE8FC}
\definecolor{C4}{HTML}{D4B1E5}
\definecolor{C5}{HTML}{E1D5E7}
\setlength{\arrayrulewidth}{2pt} % To declare the \cline width
\arrayrulecolor{blue} % If you need to change the color of \cline
\begin{document}
    \begin{table}
        \centering
        \tabulinesep = 2mm
        \tabulinestyle{2pt blue}
        \begin{tabu}to 6cm {|X[2c]|X[c]|X[c]|X[c]|X[2c]|}
            \tabucline -
            %Row 1
            &1
            &2
            &3
            &4\\ \tabucline -  
            %Row 2
            \cellcolor{C1}A
            &B
            &C
            &D
            &\cellcolor{C2}E \\ \tabucline - 
            %Row 3
            \cellcolor{black!20!C3}    
            & \multicolumn{3}{c|}{\cellcolor{C3}F} 
            & \multicolumn{1}{c|}{\cellcolor{C3}}    \\[-2pt] \tabucline{2-4} 
            %Row 4
            \cellcolor{black!20!C3}
            &\multicolumn{3}{c|}{\cellcolor{C3}G}
            & \multicolumn{1}{c|}{\cellcolor{C3} } \\[-2pt] \tabucline{2-4}  
            %Row 5
            \cellcolor{black!20!C3}
            & \multicolumn{3}{c|}{\cellcolor{C3}H}
            & \cellcolor{C3}\\[-2pt] \tabucline{2-4}  
            %Row 6
            \cellcolor{black!20!C3}
            &\cellcolor{C3}I
            &\cellcolor{C3}
            &\cellcolor{C3}J
            &\cellcolor{C3}\\[-2pt] \cline{2-2}\tabucline{4-4} %<-that is something unespected good result!
            %Row 7
            \cellcolor{black!20!C3}
            &\cellcolor{C3}
            &\cellcolor{C3}
            &\cellcolor{C3}K
            &\cellcolor{C3} \\[-2pt] \tabucline{4-4}  
            %Row 8
            \multirow{-6}{*}{\cellcolor{black!20!C3}J}
            &\multirow{-2}{*}{\cellcolor{C3}}
            &\multirow{-3}{*}{\cellcolor{C3}}
            &\cellcolor{C3}L
            &\cellcolor{C3}\\[-2pt] \tabucline{1-4}
            %Row 9
            \cellcolor{C4}
            &\cellcolor{C5}N
            &\cellcolor{C5}O
            &\cellcolor{C5}N
            &\cellcolor{C3}\\[-2pt] \tabucline{2-4}  
            %Row 10
            \multirow{-2}{*}{\cellcolor{C4}E}
            &\multicolumn{1}{l|}{\cellcolor{C5}}
            &\multicolumn{1}{l|}{\cellcolor{C5}}
            &\cellcolor{C5}Z
            &\cellcolor{C3}\\ \tabucline -
        \end{tabu}
        \caption{Table for testing colors and rules in tabu}
    \end{table}
\end{document}
Related Question