2

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
\newcommand{\leaderfill}[1]{%
  \xleaders\hbox{%
    \vbox{\baselineskip=0pt\lineskip=0pt#1}%
  }\hfill%
}
% #1 color #2 height
\newcommand{\sfill}[2]{%
  \leaderfill{\hsp{#1}{0.1pt}{#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);
%   load calc
  not load
  & \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}

enter image description here enter image description here

9
  • @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.
    – ZhiyuanLck
    Apr 27 '20 at 10:43
  • 1
    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.
    – ZhiyuanLck
    Apr 27 '20 at 11:12
  • 2
    \global\setlength is wrong syntax. See e.g. tex.stackexchange.com/a/297189/2388 Apr 27 '20 at 11:34
3

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}

enter image description here

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{
  \@ifpackageloaded{colortbl}{
    % 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
          \HH@add{\hskip\doublerulesep}%
        \else
          \HH@add{{\CT@drsc@\vrule\@width\doublerulesep}}%
        \fi
      \fi
      \@tempswatrue
      \IfNoValueTF{#2}
        {\HH@add{{\CT@arc@{\HHvline{#3}}}}}
        {\HH@add{{\color{#2}\HHvline{#3}}}}%
      \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 }{%
      \if@tempswa\HH@add{\hskip\doublerulesep}\fi\@tempswatrue
      \IfNoValueTF{#2}
        {\HH@add{\@tempc{\HHvline{#3}}\@tempc}}
        {\HH@add{\@tempc{\color{#2}\HHvline{#3}}\@tempc}}%
      \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}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.