当我用 填充多行单元格(单元格内的水平线由 绘制)时\hhline{~}
,会出现空白,我尝试用 来修复它>{\arrayrulecolor{gray}\doublerulesepcolor{gray}}=
,但垂直线的颜色也会变得混乱。
\documentclass{article}
\usepackage[table]{xcolor}
\usepackage{multirow, makecell}
\usepackage{colortbl}
\usepackage{dashrule}
\usepackage{ehhline}
\newcommand{\cdl}[2][black]{\leaders\hbox{\textcolor{#1}{\hdashrule{0.9mm}{#2}{0.3mm 0.3mm 0.3mm 0mm}}}\hfil}
\newcommand{\crs}[2][black]{\leaders\hbox{\textcolor{#1}{\rule{0.1pt}{#2}}}\hfil}
\newcommand{\vcl}[2][black]{\color{#1}\vrule width #2}
\setlength\doublerulesep{0.1pt}
\begin{document}
\begin{tabular}{!{\vcl{3pt}}c!{\vcl[green]{3pt}}c!{\vcl[yellow]{3pt}}}
\hhline{
!{\cdl[red]{1pt}}
!{\crs[red]{1pt}}
}
\multicolumn{1}{!{\vcl[green]{3pt}}c!{\vcl{2pt}}}{\cellcolor{gray}test}
& \multicolumn{1}{c!{\vcl{3pt}}}{test}\\
\hhline{
!{\cdl[orange]{1pt}}
!{\crs[teal]{2pt}}
}
\cellcolor{gray} & test\\
\hhline{
>{\arrayrulecolor{gray}\doublerulesepcolor{gray}}%
=%
!{\crs[red]{1pt}}
}
\multirow{-2}{*}{\cellcolor{gray} test some thing}
& test\\
\hhline{
!{\cdl[red]{1pt}}
!{\crs[red]{1pt}}
}
\end{tabular}
\end{document}
\hhline{
>{\rule{3pt}{1pt} \kern -3pt \arrayrulecolor{gray}\doublerulesepcolor{gray}}%
=
!{\crs[red]{1pt}}
}
解决了但是为什么呢?
我解决了这个问题,但我不知道为什么这会起作用
\hhline{
>{\rule{3pt}{1pt} \kern -3.3pt \arrayrulecolor{gray}\doublerulesepcolor{gray}}%
=
>{\kern -3pt \textcolor{green}{\rule{3pt}{1pt}}}%
!{\crs[red]{1pt}}
}
我只需要改变规则的宽度使其与垂直线的宽度相同,但是-3.3pt
和-3pt
代表什么?
答案1
更新
不要使用语法\global\setlength ...
,它从未被支持过。(见这里有解释)。要全局更改长度,etoolbox
's\deflength
是您的好朋友。它与 while 共享相同的(通常)语法,\setlength
支持额外\global\deflength
用法。
vline 的宽度为 3pt(由于!{\vcl{3pt}}
在表格前言中使用了),但|
在中使用的\hhline
只是增加了一个宽度规则\arrarrulewidth
。局部更改\arrayfulewidth
可能是一种解决方法,同时提供一个新的\hhline
前言字符,就像ehhline
包所做的那样,更为优雅。
% \usepackage{etoolbox}
\hhline{
>{\global\deflength{\arrayrulewidth}{3pt}} |
>{\global\deflength{\arrayrulewidth}{.4pt}\arrayrulecolor{gray}\doublerulesepcolor{gray}} =
>{\global\deflength{\arrayrulewidth}{3pt}\arrayrulecolor{green}} |
!{\crs[red]{1pt}}
>{\arrayrulecolor{yellow}} |
}
% restore \arrayrulewidth for following use
\global\deflength{\arrayrulewidth}{.4pt}%
是\global
必需的,因为\HH@loop
重新定义的colortbl
添加了一组额外的花括号。相关代码行:
% from colortbl.sty
\def\HH@loop{%
... ...
\ifx\@tempb|\if@tempswa
\ifx\CT@drsc@\relax
\HH@add{\hskip\doublerulesep}%
\else
\HH@add{{\CT@drsc@\vrule\@width\doublerulesep}}%
\fi
\fi\@tempswatrue
%% \vline is just "\vrule \@width \arrayrulewidth"
\HH@add{{\CT@arc@\vline}}\else
... ...
}
请注意,自hhline
v2.04(2020/01/04)以来,内部使用的空间令牌\hhline
始终被忽略。
在以下示例中,对进行了修补,以允许在 内部\HH@loop
使用。这可能会缩短OP 示例中的参数长度。V[<color>]{<width>}
\hhline{..}
\hhline
\documentclass{article}
\usepackage{array}
\usepackage{color}
% \usepackage{colortbl} % or uncomment this line
\usepackage{hhline}
\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}{!{\HHvline{1pt}}c!{\HHvline{2pt}}c!{\HHvline{3pt}}}
\hline
a & b \\ \hhline{V[red]{1pt} = V[blue]{2pt} = V[green]{3pt}}
c & d \\ \hline
\end{tabular}
\end{document}