# a bug with calc and ehhline together

Days before, I was dealing with the problem of drawing horizontal lines between colored multirow cell with \hhline. I tried two method and took the second at last. But I found there is a bug in the first method if calc is loaded.

All things are in my example code. Comment the calc package, the vertical line (red and teal ones) below the third row will be shown normally.

\documentclass{article}
\usepackage[table]{xcolor}
\usepackage{tikz}
\usepackage{multirow}
\usepackage{colortbl}
\usepackage{ehhline}
% \usepackage{calc} % make method 1 not work

%% vertical line
% vertical colored line #1 color #2 width
\newcommand{\vsl}[2]{\color{#1}\vrule width #2}
% colored solid line pattern
% #1 color #2 width #3 height
\newcommand{\hsp}[3]{\hbox{\textcolor{#1}{\rule{#2}{#3}}}}
% #1 top fill #2 bottom fill
\vbox{\baselineskip=0pt\lineskip=0pt#1}%
}\hfill%
}
% #1 color #2 height
\newcommand{\sfill}[2]{%
}
%% vline settings
% #1 rule width #2 color
\newcommand{\setvline}[2]{%
\global\setlength\arrayrulewidth{#2}\arrayrulecolor{#1}%
}

\begin{document}
\begin{tabular}{
!{\vsl{red}{5pt}}c
!{\vsl{teal}{5pt}}p{0.5cm}
!{\vsl{blue}{3pt}}
}
% row 1
\cellcolor{gray}
& \cellcolor{yellow}\\
\hhline{
~ % blank in merged cell
!{\sfill{black}{3pt}}
}
% row 2
\cellcolor{gray}
& \cellcolor{yellow}\\
\hhline{
!{\sfill{gray}{3pt}} % overlap the vertical line
!{\sfill{black}{3pt}}
}
% row 3
\cellcolor{gray} third row
& \cellcolor{orange}\\
% first method: set arrayrulewidth and arraycolor
% not work with calc
\hhline{
>{\setvline{red}{5pt}}|
!{\sfill{gray}{3pt}}
>{\setvline{teal}{5pt}}|
!{\sfill{black}{3pt}}
}
% row 4
\cellcolor{gray}\tikz[->, baseline=-.5ex] \draw (0, 0) -- (-1ex, 1ex);
& \cellcolor{pink}\\
% second method: use box
\hhline{
>{\vsl{red}{5pt}}
!{\sfill{gray}{3pt}}
>{\vsl{teal}{5pt}}
!{\sfill{black}{3pt}}
}
% row 5
\cellcolor{gray}\multirow{-5}*{}
& \cellcolor{cyan}\\
\end{tabular}
\end{document}


• @StevenB.Segletes I have checked that the version of the package is 4.01, the latest version. And make sure that pdflatex and xelatex will both reproduce the problem. By the way , I'm using texlive 2020. Apr 27 '20 at 10:43
• I rechecked and in "row 3" only, if I load stackengine, the solid red vertical bar gets a smll gray finger on the left side. Same for teal bar. Is this the essence of the cited issue? Apr 27 '20 at 10:55
• The stackengine package loads the calc package, and it is calc that is causing the issue. If you load calc instead of stackengine, you will see the same issue. Thus, there seems to be an incompatibility with calc. Apr 27 '20 at 11:07
• yes, sorry for the bad example, I just wonder why this will happen and report this issue. Thanks for reply. Apr 27 '20 at 11:12
• \global\setlength is wrong syntax. See e.g. tex.stackexchange.com/a/297189/2388 Apr 27 '20 at 11:34

The MWE can be simplified to

\documentclass{article}
\usepackage[table]{xcolor}
\usepackage{ehhline}

\usepackage{stackengine}

\begin{document}
\begin{tabular}{p{0.5cm} !{\color{yellow}\vrule width 5pt} p{0.5cm}}
a & b \\
\hhline{
-
>{\global\setlength\arrayrulewidth{5pt}\arrayrulecolor{yellow}}|
>{\global\setlength\arrayrulewidth{.4pt}} -
}
c & d
\end{tabular}
\end{document}


From question comments, it is calc, loaded by stackengine, that redefines \setlength and forbids the never-supported syntax \global\setlength.

To change a length globally, you can use

\global\deflength{<length>}{<glue expression>}


where \deflength is defined by etoolbox package.

Or, you can avoid the need to change \arrayrulewidth globally in >{...} by using the new hhline preamble V[<color>]{<width>} from my previous answer.

Inside \hhline, V[<color>]{<width>} acts like | with specific color and width. A full example:

\documentclass{article}
\usepackage[table]{xcolor}
\usepackage{ehhline}

\usepackage{stackengine}

\usepackage{xpatch} % or etoolbox
\usepackage{xparse}

\makeatletter
% based on \vline from latex2e
\def\HHvline#1{\vrule\@width#1}

\AtBeginDocument{
% based on \ifx\@tempb|...\else part of \HH@loop from colortbl.sty
\NewDocumentCommand{\HH@preamble@V}{ m o m }{%
\if@tempswa
\ifx\CT@drsc@\relax
\else
\fi
\fi
\@tempswatrue
\IfNoValueTF{#2}
\HH@let V%
}
\xpatchcmd\HH@loop
{\PackageWarning{hhline}}
{%
\ifx\@tempb V% V[<color>]{<width>}
\let\next\HH@preamble@V
\else
\PackageWarning{hhline}%
}
{}{\fail}
}{
% based on \ifx\@tempb|...\else part of \HH@loop from hhline.sty
\NewDocumentCommand{\HH@preamble@V}{ m o m }{%
\IfNoValueTF{#2}
\HH@let V%
}
\xpatchcmd\HH@loop
{\PackageWarning{hhline}}
{%
\ifx\@tempb V% V[<color>]{<width>}
\let\next\HH@preamble@V
\else
}
{}{\fail}
}
\xpatchcmd\HH@loop
{\fi\fi\fi}
{\fi\fi\fi\fi}
{}{\fail}
}
\makeatother

\begin{document}
\begin{tabular}{p{0.5cm} !{\color{yellow}\vrule width 5pt} p{0.5cm}}
a & b \\
\hhline{- V[yellow]{5pt} >{\arrayrulecolor{yellow}}-}
c & d
\end{tabular}
\end{document}