Variable-width horizontal rules with \cline intrude cell text
Both problems are related. \cline
has to support several \cline
s in a row, e.g.:
\documentclass{article}
\begin{document}
\begin{tabular}{*{5}{c}}
1 & 2 & 3 & 4 & 5\\
\cline{1-1}\cline{3-3}\cline{5-5}
A & B & C & D & E
\end{tabular}
\end{document}
Therefore \cline
cannot move down like \hline
, the definition of \cline
is (latex.ltx
):
\def\cline#1{\@cline#1\@nil}
\def\@cline#1-#2\@nil{%
\omit
\@multicnt#1%
\advance\@multispan\m@ne
\ifnum\@multicnt=\@ne\@firstofone{&\omit}\fi
\@multicnt#2%
\advance\@multicnt-#1%
\advance\@multispan\@ne
\leaders\hrule\@height\arrayrulewidth\hfill
\cr
\noalign{\vskip-\arrayrulewidth}}
In the last step \cline
moves back to the original vertical position.
But the vertical space for the line can be added after the \cline
s, e.g.:
\cline{...}\cline{...}\noalign{\vskip\arrayrulewidth}
Applied to your example, it can be added to macro \whline
. This fixes also the problem with \cellcolor
:
\documentclass{article}
\usepackage{array}
\usepackage{colortbl}
\begin{document}
\newcolumntype{I}{!{\vrule width 3pt}}
\newlength\savedwidth
\newcommand\whline[1]{%
\noalign{%
\global\savedwidth\arrayrulewidth\global\arrayrulewidth 6pt%
}%
\cline{#1}%
\noalign{\vskip\arrayrulewidth}%
\noalign{\global\arrayrulewidth\savedwidth}%
}
\begin{tabular}{|cIc|c|}\hline
A & B & C \\ \hline
X & \cellcolor{red}Y & Z \\ \whline{1-3}
\cellcolor{green}100 & 10 & 1 \\ \hline
\end{tabular}
\end{document}
Here is Heiko's example using cals
package as an alternative:
\documentclass{article}
\usepackage{xcolor}
\usepackage{cals}
\begin{document}
\begin{calstable}
\colwidths{{10mm}{10mm}{10mm}}
\makeatletter
\brow
\cell{A}
\def\cals@borderL{2pt}\cell{B}\let\cals@borderL=\relax
\cell{C}
\erow
\brow
\def\cals@borderB{3pt}
\cell{X}
\def\cals@borderL{2pt}\def\cals@bgcolor{red}
\cell{Y}\let\cals@borderL=\relax\def\cals@bgcolor{}
\cell{Z}
\erow
\let\cals@borderB=\relax
\brow
\def\cals@bgcolor{green}\cell{100}\def\cals@bgcolor{}
\def\cals@borderL{2pt}\cell{10}\let\cals@borderL=\relax
\cell{1}
\erow
\end{calstable}
\end{document}