11

The intersection of horizontal clines and vertical lines in tables look weird. Here is a MWE:

\documentclass[11pt,oneside]{article}
%\usepackage{array}

\begin{document}

\begin{table}
\centering
\begin{tabular}{c|c|c|c}
\cline{2-3}
a&b&c&d\\
\cline{2-3}
\end{tabular}  
\end{table}

\end{document}

Here is the output:

enter image description here

As you can see, there are small gaps at the intersections of the horizontal and the vertical lines at the two corners at the bottom. Interestingly, the two corners at the top are fine.

Now if the array package is loaded (simply uncomment in the code above), then I get:

enter image description here

The weird gap is gone at the lower right corner but it still persists at the lower left corner.

I did a considerable amount of research into this (see, e.g., this post) but did not find any definitive solution. Any suggestions would be greatly appreciated.

(I am aware of the existence of hhline but I read in another post that it might be prone to similar intersection issues, so I’d prefer a solution without it.)

4
  • If it only partially works loading array, maybe this is due to tthe oneside option the ‘article’? ;o)
    – Bernard
    Commented Aug 26, 2019 at 15:43
  • @Bernard Nice catch! Alas, the output is the same upon taking out oneside.
    – triple_sec
    Commented Aug 26, 2019 at 15:53
  • I just found funny that a one-side defect happened with the oneside option…
    – Bernard
    Commented Aug 26, 2019 at 15:55
  • @Bernard It would make sense, but it would also be a surprise if TeX were that predictable... :-)
    – triple_sec
    Commented Aug 26, 2019 at 18:37

3 Answers 3

8

Don't know why it happens, but here's a fix...diminish the \\ by \arrayrulewidth (EDITED to reflect \arrayrulewidth rather than \fboxrule, hat tip: David Carlisle).

\documentclass[11pt,oneside]{article}
%\usepackage{array}

\begin{document}

\begin{table}
\centering
\begin{tabular}{c|c|c|c}
\cline{2-3}
a&b&c&d\\[-\arrayrulewidth]
\cline{2-3}
\end{tabular}  
\end{table}

\end{document}

enter image description here

If one is concerned that this approach shrinks the height of the cell by -\arrayrulewidth, then just compensate by adding an extra \arrayrulewidth to the depth of the line before the shrunken \\. Compare the original box on the left with the revised on the right.

\documentclass[11pt,oneside]{article}
%\usepackage{array}
\newcommand\mystrut{\rule[\dimexpr-\dp\strutbox-\arrayrulewidth]{0pt}{%
  \dimexpr\baselineskip+\arrayrulewidth}}
\begin{document}

\begin{table}
\centering
\begin{tabular}{c|c|c|c}
\cline{2-3}
a&b&c&d\\
\cline{2-3}
\end{tabular}%
%
\begin{tabular}{c|c|c|c}
\cline{2-3}
a&b&c&d\mystrut\\[-\arrayrulewidth]
\cline{2-3}
\end{tabular}  
\end{table}

\end{document}

enter image description here

4
  • This is clever, thank you! Doesn’t it shrink the height of cells, though? (I know it’s a PITA and I probably shouldn’t do this, but I like to control cell heights as much as TeX lets me.)
    – triple_sec
    Commented Aug 26, 2019 at 14:46
  • 1
    @triple_sec Please see my edit. Commented Aug 26, 2019 at 14:54
  • 2
    Fboxrule Is used for fbox not tables atrayrulewifth Commented Aug 26, 2019 at 16:32
  • 1
    Thank you for this great answer! It turns out my cells had a little extra blank space left at the bottom to begin with, and adding \\[-\fboxrule] at the end of each line fixes that, too. The corner gaps are now gone and the text seems to have become perfectly aligned vertically in the cells as well. (I’m not particularly concerned about the difference between arrayrulewidth and fboxrule, since both lengths are 0.4pt according to my settings.)
    – triple_sec
    Commented Sep 1, 2019 at 19:45
12

You get precise control with \hhline:

\documentclass{article}
\usepackage{hhline}

\begin{document}

\begin{tabular}{c|c|c|c}
\hhline{~|-|-|~}
a&b&c&d\\
\hhline{~|-|-|~}
\end{tabular}

\end{document}

enter image description here

  • ~ means no rule for the cell,
  • | means an intersection with a vertical rule,
  • - means a rule for the cell.
1
  • Thank you for your answer. +1. I had not been familiar with \hhline before encountering this gap issue with \cline and read somewhere (the exact source eludes my memory) that it may be prone to intersection issues, too, so I’m a little wary of starting to use it. The answer by @StevenB.Segletes is admittedly more cumbersome to code, but it gives me a greater sense of control over how my tables look.
    – triple_sec
    Commented Sep 1, 2019 at 19:50
2

For information, {NiceTabular} of nicematrix provides tools to draw rules in a tabular with a perfect result (the rules are drawn with PGF/Tikz after the construction of the array).

\documentclass[11pt,oneside]{article}
\usepackage{nicematrix}

\begin{document}

\begin{table}
\centering
\begin{NiceTabular}{cccc}
a&\Block[hvlines]{1-2}{}b&c&d\\
\end{NiceTabular}  
\end{table}

\end{document}

You need several compilations (because nicematrix uses PGF/Tikz nodes under the hood).

Output of the above code

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .