Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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}
share|improve this question

2 Answers 2

up vote 7 down vote accepted

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.

share|improve this answer
1  
Thank you for the effort, I'm glad you people are not only competent but also quick and friendly. –  Dennis Aug 2 '12 at 15:30
1  
Could you please explain a bit more on how to apply colour to \hhline. I don't quite understand >{}. Thank you in advance. –  71GA Nov 18 '13 at 21:38
    
@71GA There are lots of examples in the hhline documentation, texdoc hhline then search for Richard –  David Carlisle Nov 18 '13 at 21:44
    
I found this document ctan.ijs.si/tex-archive/macros/latex/required/tools/hhline.pdf but there is no description on how to use color. There is allso no Richard string inside. I don't think I understand your reply. –  71GA Nov 18 '13 at 22:15
2  
@71GA sorry the coloured hhline examples are in colortbl (by the way you should have hhline documentation on your local system, not only on ctan) but anyway page 6 of texdoc.net/texmf-dist/doc/latex/colortbl/colortbl.pdf –  David Carlisle Nov 18 '13 at 22:18
  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}
share|improve this answer
    
@1. - I chose the color black only to contrast the white line. The cells will not be black in the final document, as I said, but thanks for the effort =) –  Dennis Aug 2 '12 at 15:28

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.