The problem
Let's say I want to have more than rules in two different colors in the same row ... how can I make it work?
Here is a minimal example:
\documentclass{article}
\usepackage{colortbl}
\usepackage{booktabs}
\begin{document}
\begin{table}[ht]
\begin{tabular}{llll}
\toprule
A & B & alpha & beta\\
\arrayrulecolor{black} \cmidrule[1pt](l){1-1} \arrayrulecolor{red} \cmidrule[1pt](r){2-2} \arrayrulecolor{black} \cmidrule[1pt](l){3-3} \arrayrulecolor{black} \cmidrule[1pt](r){4-4}
1 & 5 & 10 & 100\\
2 & 6 & 11 & 101\\
2 & 7 & 12 & 102\\
3 & 8 & 13 & 103\\
\bottomrule
\end{tabular}
\end{table}
\end{document}
What happens is that with each call of \arrayrulecolor{}, the corresponding cmidrule is moved down.
The solution is a macro that corrects the positioning, but there is a problem with it.
The problem with the earlier solution
The solution mentioned here: How to omit vertical realignment when using cmidrule in different colors? does not handle varying widths correctly
\documentclass{article}
\usepackage{colortbl}
\usepackage{booktabs}
\newcommand{\corcmidrule}[1][2pt]{% \corcmidrule[<len>]
\[\dimexpr-\normalbaselineskip-\belowrulesep-\aboverulesep-#1\relax]%
}
\begin{document}
\begin{table}[ht]
\begin{tabular}{llll}
\toprule
A & B & alpha & beta\\
\arrayrulecolor{black}\cmidrule[1pt](l){1-1}
\corcmidrule[2pt]\arrayrulecolor{black}\cmidrule[2pt](r){2-2}
\corcmidrule[5pt]\arrayrulecolor{black}\cmidrule[5pt](l){3-3}
\corcmidrule[1pt]\arrayrulecolor{black}\cmidrule[1pt](r){4-4}
1 & 5 & 10 & 100\\
2 & 6 & 11 & 101\\
2 & 7 & 12 & 102\\
3 & 8 & 13 & 103\\
\bottomrule
\end{tabular}
\end{table}
\end{document}
What's wrong with this? Consider what it looks like without the macro:
\documentclass{article}
\usepackage{colortbl}
\usepackage{booktabs}
\newcommand{\corcmidrule}[1][2pt]{% \corcmidrule[<len>]
\[\dimexpr-\normalbaselineskip-\belowrulesep-\aboverulesep-#1\relax]%
}
\begin{document}
\begin{table}[ht]
\begin{tabular}{llll}
\toprule
A & B & alpha & beta\\
\arrayrulecolor{black}\cmidrule[1pt](l){1-1}
\cmidrule[2pt](r){2-2}
\cmidrule[5pt](l){3-3}
\cmidrule[1pt](r){4-4}
1 & 5 & 10 & 100\\
2 & 6 & 11 & 101\\
2 & 7 & 12 & 102\\
3 & 8 & 13 & 103\\
\bottomrule
\end{tabular}
\end{table}
\end{document}
It seems that these would be the right adjustments.
\begin{table}[ht]
\begin{tabular}{llll}
\toprule
A & B & alpha & beta\\
\arrayrulecolor{black}\cmidrule[1pt](l){1-1}
\corcmidrule[1pt]\arrayrulecolor{black}\cmidrule[2pt](r){2-2}
\corcmidrule[3pt]\arrayrulecolor{black}\cmidrule[5pt](l){3-3}
\corcmidrule[5pt]\arrayrulecolor{black}\cmidrule[1pt](r){4-4}
1 & 5 & 10 & 100\\
2 & 6 & 11 & 101\\
2 & 7 & 12 & 102\\
3 & 8 & 13 & 103\\
\bottomrule
\end{tabular}
\end{table}
A bigger example
\begin{table}[ht]
\begin{tabular}{lllll}
\toprule
A & B & alpha & beta & gamma\\
\arrayrulecolor{black}\cmidrule[1pt](l){1-1}
\corcmidrule[1pt]\arrayrulecolor{black}\cmidrule[2pt](){2-2}
\corcmidrule[2pt]\arrayrulecolor{black}\cmidrule[2pt](){3-3}
\corcmidrule[2pt]\arrayrulecolor{black}\cmidrule[5pt](){4-4}
\corcmidrule[5pt]\arrayrulecolor{black}\cmidrule[1pt](){5-5}
1 & 5 & 10 & 100 & 1\\
2 & 6 & 11 & 101 & 1\\
2 & 7 & 12 & 102 & 1\\
3 & 8 & 13 & 103 & 1\\
\bottomrule
\end{tabular}
\end{table}
Could this be put into a macro? One needs to pull the width of the previous rule.




hhline? – Bernard Jan 30 '21 at 17:17\cmidrulemakes it easy, trim left, right or both. This is for programmatically creating tables. Inserting the right widths at the right place is not a problem, however, it doesn't help readability. So I want to create a table programmatically, but keep enough readability for manual tweaking. – Inferrator Jan 30 '21 at 17:31