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

4
  • I would guess {\color{#4}\leaders\hrule\@height#3\hfill} would work (you should anyway add a % or remove the white space after \color) Aug 25, 2018 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. Aug 25, 2018 at 19:13
  • I added an image to my answer, I suspect you have omitted a % somewhere. Aug 25, 2018 at 19:18
  • Thanks! I had omitted the % after the \leaders\hrule\@height#3\hfill} line. Aug 25, 2018 at 19:22

1 Answer 1

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}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .