3

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%
    \advance\@multispan\m@ne
    \ifnum\@multicnt=\@ne\@firstofone{&\omit}\fi
    \@multicnt#2%
    \advance\@multicnt-#1%
    \advance\@multispan\@ne
    \color{#4}
    \leaders\hrule\@height#3\hfill
    \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}

enter image description here

Jim Ratliff
  • 1,049

1 Answers1

4

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

enter image description here

\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%
    \advance\@multispan\m@ne
    \ifnum\@multicnt=\@ne\@firstofone{&\omit}\fi
    \@multicnt#2%
    \advance\@multicnt-#1%
    \advance\@multispan\@ne
    {\color{#4}%
    \leaders\hrule\@height#3\hfill}%
    \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}
David Carlisle
  • 757,742