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}
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}
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 :
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]
, wherebar
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: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:The code is based on easy to read structure: