I have come to learn how to make a variable-width horizontal rule with \hline from the LaTeX companion and with \cline from Horizontal rule with adjustable height behaving like \cline{n-m}. But the problem with the horizontal \cline is that the rule intrudes on the texts in the cells below the \cline. However, \hline doesn't seem to have this intruding problem. The minimal working example below shows the differences.
\documentclass{article}
\usepackage{array}
\begin{document}
\newcolumntype{I}{!{\vrule width 3pt}}
\newlength\savedwidth
\newcommand\whline{\noalign{\global\savedwidth\arrayrulewidth\global\arrayrulewidth 6pt}%
\hline
\noalign{\global\arrayrulewidth\savedwidth}}
\begin{tabular}{|cIc|c|}\hline
A & B & C \\ \hline
X & Y & Z \\ \whline
100 & 10 & 1 \\ \hline
\end{tabular}
\renewcommand\whline[1]{\noalign{\global\savedwidth\arrayrulewidth\global\arrayrulewidth 6pt}%
\cline{#1}
\noalign{\global\arrayrulewidth\savedwidth}}
\begin{tabular}{|cIc|c|}\hline
A & B & C \\ \hline
X & Y & Z \\ \whline{1-3}
100 & 10 & 1 \\ \hline
\end{tabular}
\end{document}
Another problem with using \cline in the definition of the thick horizontal rule (whline above) is that a \cellcolor command will wipe out the portion of the horizontal rule that is above the cell, no matter how thick I defined the whline to be. Using \hline in the definition of whline does not cause this problem with using colors in a cell.
I suspect that the vertical position, starting below which is the territory of a cell, for \hline and for \cline differs. For \hline, a cell starts below the bottom boundary of the horizontal rule, while for \cline, a cell starts below the top boundary of the rule? Anyone enlighten me please!
NOTE: I do want to use variable-width \cline (either thick or thin like the example showed), but I want to avoid these intruding problems.
Best Answer
Both problems are related.
\cline
has to support several\cline
s in a row, e.g.:Therefore
\cline
cannot move down like\hline
, the definition of\cline
is (latex.ltx
):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.:Applied to your example, it can be added to macro
\whline
. This fixes also the problem with\cellcolor
: