TransWikia.com

hhline adds white line where no line is intended

TeX - LaTeX Asked on July 29, 2021

In a table, containing colored cells, i want to have a hline dividing only some cells, similar to cline but compatible with coloring single cells with cellcolor, which is possible by using hhline with fitting parameters.

Now I have come to the appended code, which results in:
tables_hhline

There are two points I want to work around.

First, the black cells should not be crossed by a white line. Since they will not be black in the final document, I need them to be not black, either. Is there a way to not draw any line at all? These cells should look like a multirow cell, colored consistently.

The second problem are the hline fragments at the right end of the table. How can I get rid of them?

Complete code:

documentclass[11pt]{article}

usepackage{color}
usepackage{colortbl}
usepackage{multirow}
usepackage{hhline}

setlength{arrayrulewidth}{1pt}


begin{document}
% Empty table
begin{tabular}{*{5}{!{vrule width 1.5pt}p{1.5cm}}!{vrule width 1.5pt}l}
centering 4 &
centering 10 &
centering 24 &
centering 48 &
centering 72 & hhline{*{5}{|-}|~|}
 &  &  &  &  & Optic tectum  hhline{*{2}{|~}*{3}{|-}|~|}
 &  &  &  &  & Retina  hhline{*{2}{|~}*{3}{|-}|~|}
 &  &  &  &  & Myomeres  hhline{*{5}{|-}|~|}
 &  &  &  &  & Arches  hhline{*{5}{|-}|~|}
end{tabular} 

hspace*{1cm}

% Partically filled table
begin{tabular}{*{5}{!{vrule width 1.5pt}p{1.5cm}}!{vrule width 1.5pt}l}
centering 4 &
centering 10 &
centering 24 &
centering 48 &
centering 72 & hhline{*{5}{|-}|~|}
 & cellcolor{black} &  & cellcolor{green} &  & Optic tectum  hhline{*{2}{|~}*{3}{|-}|~|}
 & cellcolor{black} &  & cellcolor{red} &  & Retina  hhline{*{2}{|~}*{3}{|-}|~|}
 & cellcolor{black} &  & cellcolor{blue} &  & Myomeres  hhline{*{5}{|-}|~|}
 & cellcolor{blue} &  & cellcolor{yellow} &  & Arches  hhline{*{5}{|-}|~|}
end{tabular}

end{document}

3 Answers

You are specifying a final hhline fragment

hhline{*{2}{|~}*{3}{|-}|~|}

You need

 hhline{*{2}{|~}*{3}{|-}|~}

The "white line" is not a rule drawn over the black background it is just a lack of background, thus you need to fill it, the easiest way, as shown in the previous question is not to use ~ in the hhline (which does exactly what you ask and does not draw any line at all) but instead use - but colour the rule using >{...} to match the cell colour.

Correct answer by David Carlisle on July 29, 2021

  1. If the look of black cells should be multirow-esque, then colouring the lines black would do it. For this, I used a - instead of ~ to draw the horizontal rules for the second column;
  2. Using | indicates a "vline which 'cuts' through a double (or single) hline" (according to the hhline documentation). Removing this from your hhline specification at the end drops the "hline fragments."
  3. Since you're using vline 1.5pt as your column divisions, you might as well use

    setlength{arrayrulewidth}{1.5pt}
    

    to have a consistent look for your table. Otherwise you will notice little indents in your vertical rules.

Here's a MWE showcasing the above:

enter image description here

documentclass[11pt]{article}
%usepackage{color}% http://ctan.org/pkg/color
%usepackage{multirow}% http://ctan.org/pkg/multirow
usepackage{colortbl}% http://ctan.org/pkg/colortbl
usepackage{hhline}% http://ctan.org/pkg/hhline

begin{document}
% Empty table
setlength{arrayrulewidth}{1pt}%
begin{tabular}{*{5}{!{vrule width 1.5pt}p{1.5cm}}!{vrule width 1.5pt}l}
centering 4 &
centering 10 &
centering 24 &
centering 48 &
centering 72 & hhline{*{5}{|-}|~|}
 &  &  &  &  & Optic tectum  hhline{*{2}{|~}*{3}{|-}|~|}
 &  &  &  &  & Retina  hhline{*{2}{|~}*{3}{|-}|~|}
 &  &  &  &  & Myomeres  hhline{*{5}{|-}|~|}
 &  &  &  &  & Arches  hhline{*{5}{|-}|~|}
end{tabular}

bigskip

% Partically filled table
setlength{arrayrulewidth}{1.5pt}%
begin{tabular}{*{5}{|p{1.5cm}}|l}
centering 4 &
centering 10 &
centering 24 &
centering 48 &
centering 72 & hhline{*{5}{|-}|~}
 & cellcolor{black} &  & cellcolor{green} &  & Optic tectum  hhline{|~*{4}{|-}|~}
 & cellcolor{black} &  & cellcolor{red} &  & Retina  hhline{|~*{4}{|-}|~}
 & cellcolor{black} &  & cellcolor{blue} &  & Myomeres  hhline{*{5}{|-}|~}
 & cellcolor{blue} &  & cellcolor{yellow} &  & Arches  hhline{*{5}{|-}|~}
end{tabular}

end{document}

Answered by Werner on July 29, 2021

You can easily construct that table with {NiceTabular} of nicematrix. The rules specified the command Hline (of nicematrix) are not drawn in the blocks (constructed by the command Block).

documentclass[11pt]{article}
usepackage{nicematrix}
setlength{arrayrulewidth}{1pt}

begin{document}

begin{NiceTabular}{*{5}{p{1.5cm}}}[colortbl-like,last-col,vlines,rules/width=1.5pt]
centering 4 &
centering 10 &
centering 24 &
centering 48 &
centering 72 & 
Hline
Block{*-1}{} 
 & Block[fill=red!15]{3-1}{} 
    &  & cellcolor{green} &  & Optic tectum  
Hline
 &  &  & cellcolor{red} &  & Retina  
Hline
 &  &  & cellcolor{blue} &  & Myomeres  
Hline
 & cellcolor{blue} 
    &  & cellcolor{yellow} &  & Arches  
Hline
end{NiceTabular}

end{document}

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

Output of the above code

Answered by F. Pantigny on July 29, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP