# \color in a \cline-like macro causes extra line when after the last row

I have a macro, e.g., \clineThicknessColor{2-3}{1.5pt}{blue}, that is basically \cline plus a thickness and a color (thanks to Hood Chatham's answer to my earlier question).

It's working fine, except when the macro is entered as the last row of a tabular, in which case it causes (A) an extra line of the tabular and (B) an extra vertical line between the first and second columns in that added row. (See MWE below and the purple oval in the output.)

The location of the extra vertical line, between the first and second column, doesn't depend on what columns the \cline spans.

If I comment out the \color{#4} line of the macro, the problem goes away (as does the desired color change).

The problem does not occur with regular stock \cline.

What is causing this? And how do I fix it (achieve the color change without the extraneous row and vertical line)?

(Let me preemptively disclaim that I know that a well-formatted table shouldn't have vertical lines in the first place.)

\documentclass{article}
\usepackage{xcolor}

\makeatletter
\def\clineThicknessColor#1#2#3{\@ClineThicknessColor#1\@nil{#2}{#3}}
%   Example usage: \clineThicknessColor{2-3}{1.5pt}{blue}
\def\@ClineThicknessColor#1-#2\@nil#3#4{%
\omit
\@multicnt#1%
\ifnum\@multicnt=\@ne\@firstofone{&\omit}\fi
\@multicnt#2%
\color{#4}
\cr}
\makeatother

\begin{document}
\begin{tabular}{c | c | c | c}
\hline
A & B & C & D\\
\clineThicknessColor{2-3}{1.5pt}{blue}
E & F & G & H\\
\clineThicknessColor{3-4}{1pt}{red}
\end{tabular}
\end{document}


• I would guess {\color{#4}\leaders\hrule\@height#3\hfill} would work (you should anyway add a % or remove the white space after \color) – David Carlisle Aug 25 '18 at 18:56
• @DavidCarlisle, please see my additional edit. Your suggestion causes the \clines to be a little less wide than before, not quite reaching the final column. – Jim Ratliff Aug 25 '18 at 19:13
• I added an image to my answer, I suspect you have omitted a % somewhere. – David Carlisle Aug 25 '18 at 19:18
• Thanks! I had omitted the % after the \leaders\hrule\@height#3\hfill} line. – Jim Ratliff Aug 25 '18 at 19:22

You need to restore the colour in the same cell, so:

\documentclass{article}
\usepackage{xcolor}

\makeatletter
\def\clineThicknessColor#1#2#3{\@ClineThicknessColor#1\@nil{#2}{#3}}
%   Example usage: \clineThicknessColor{2-3}{1.5pt}{blue}
\def\@ClineThicknessColor#1-#2\@nil#3#4{%
\omit
\@multicnt#1%
\ifnum\@multicnt=\@ne\@firstofone{&\omit}\fi
\@multicnt#2%
{\color{#4}%