TransWikia.com

cellcolor overwrites table lines (hhline)

TeX - LaTeX Asked by BHamza on September 26, 2020

After following the questions related to the same topic where the problem was using cline, I used the suggestions based on another related question. However, I am still facing the same problem where the horizontal lines are covered by the color of the cell. The confusing part is that it is not consistent. It worked for some lines but not the others.

Sample table

documentclass[journal]{IEEEtran}

usepackage{amssymb, amsmath, amsthm, amsfonts}
usepackage{tabularx}
usepackage[dvips]{graphicx}
usepackage{epsfig}
usepackage{algorithm,algorithmic}
usepackage{subfigure}
usepackage[table]{xcolor}% http://ctan.org/pkg/xcolor
usepackage{multirow}
usepackage{footnote}
usepackage{arydshln}
usepackage[skip=5pt]{caption}   % Unifies the distance between caption and float
newtheorem{theorem}{Theorem}
newtheorem{definition}{Definition}
newtheorem{notation}{Notation}
newtheorem{lemma}{Lemma}
newtheorem{property}{Property}
DeclareMathOperator*{argmax}{arg,max} %Defines a new operation argmax with no space
usepackage[hyphens]{url}
usepackage{array}
usepackage{rotating}
usepackage{color}
usepackage{xcolor}
usepackage{ragged2e}
newcolumntype{P}[1]{>{RaggedRight}p{#1}}
usepackage{cite}
bibliographystyle{IEEEtran}
usepackage{pifont}% http://ctan.org/pkg/pifont
newcommand{cmark}{ding{51}}%
newcommand{xmark}{ding{55}}%
usepackage{bm} % For bold math notations use bm{$..$}
usepackage{arydshln} % For dashed lines. hdashline and cdashline commands which are the dashed counterparts of hline and cline

usepackage[table]{xcolor}% http://ctan.org/pkg/xcolor
usepackage{hhline}

usepackage{enumitem}

newcommand{inchsign}{^{primeprime}}

usepackage{bm} % For bold math notations use bm{$..$}



begin{document}

begin{table*}[htpb]
begin{minipage}{linewidth}
renewcommand{thefootnote}{thempfootnote}
center{caption{label{tab:classification} Classification.}
scalebox{1}
{{
begin{tabular}{m{3cm} m{1cm} m{0.75cm} m{0.25cm} m{2.7cm} m{1.45cm} m{1.45cm} m{1.45cm} m{1.45cm} m{1.45cm}}
hhline{*{10}{|-}|}
multicolumn{5}{|c|}{multirow{2}{*}{Proposed Classification}} & multicolumn{1}{c|}{multirow{2}{*}{UShort}} & multicolumn{1}{c|}{multirow{2}{*}{Short}} & multicolumn{1}{c|}{multirow{2}{*}{Medium}} & multicolumn{1}{c|}{multirow{2}{*}{Long}} & multicolumn{1}{c|}{multirow{2}{*}{ULong}}
multicolumn{5}{|c|}{} & multicolumn{1}{c|}{} & multicolumn{1}{c|}{} & multicolumn{1}{c|}{} & multicolumn{1}{c|}{} & multicolumn{1}{c|}{}  hhline{*{10}{|-}|}

multicolumn{1}{|c|}{multirow{12}{*}{Indoor}} & multicolumn{1}{c|}{multirow{7}{*}{Point}} &  multicolumn{1}{c|}{multirow{4}{*}{LOS}} & multicolumn{1}{c|}{multirow{2}{*}{F}} & multicolumn{1}{c|}{multirow{2}{*}{I / PC / LOS / F}}  &  multicolumn{1}{c|}{multirow{2}{*}{parbox{1.45cm}{}}} & multicolumn{1}{c|}{} & multicolumn{1}{c|}{}  & multicolumn{1}{c|}{cellcolor{blue!25}} & multicolumn{1}{c|}{cellcolor{blue!25}} 
multicolumn{1}{|c|}{multirow{12}{*}{$(I)$}} & multicolumn{1}{c|}{multirow{7}{*}{Coverage}} & multicolumn{1}{c|}{} & multicolumn{1}{c|}{} & multicolumn{1}{c|}{} & multicolumn{1}{c|}{} & multicolumn{1}{c|}{} & multicolumn{1}{c|}{} & multicolumn{1}{c|}{cellcolor{blue!25}} & multicolumn{1}{c|}{cellcolor{blue!25}} 

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


multicolumn{1}{|c|}{} & multicolumn{1}{c|}{multirow{7}{*}{$(PC)$}} &  multicolumn{1}{c|}{} & multicolumn{1}{c|}{multirow{2}{*}{M}} & multicolumn{1}{c|}{multirow{2}{*}{I / PC / LOS / M}}  &  multicolumn{1}{c|}{multirow{2}{*}{parbox{1.45cm}{}}} & multicolumn{1}{c|}{} & multicolumn{1}{c|}{}  & multicolumn{1}{c|}{cellcolor{blue!25}} & multicolumn{1}{c|}{cellcolor{blue!25}}   
multicolumn{1}{|c|}{} & multicolumn{1}{c|}{} & multicolumn{1}{c|}{} & multicolumn{1}{c|}{} & multicolumn{1}{c|}{} & multicolumn{1}{c|}{} & multicolumn{1}{c|}{} & multicolumn{1}{c|}{} & multicolumn{1}{c|}{cellcolor{blue!25}} & multicolumn{1}{c|}{cellcolor{blue!25}} 

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

multicolumn{1}{|c|}{} & multicolumn{1}{c|}{} &  multicolumn{1}{c|}{multirow{4}{*}{NLOS}} & multicolumn{1}{c|}{multirow{2}{*}{F}} & multicolumn{1}{c|}{multirow{2}{*}{I / PC / NLOS / F}}  &  multicolumn{1}{c|}{multirow{2}{*}{parbox{1.45cm}{}}} & multicolumn{1}{c|}{} & multicolumn{1}{c|}{}  & multicolumn{1}{c|}{cellcolor{blue!25}} & multicolumn{1}{c|}{cellcolor{blue!25}}  
multicolumn{1}{|c|}{} & multicolumn{1}{c|}{} & multicolumn{1}{c|}{} & multicolumn{1}{c|}{} & multicolumn{1}{c|}{} & multicolumn{1}{c|}{} & multicolumn{1}{c|}{} & multicolumn{1}{c|}{} & multicolumn{1}{c|}{cellcolor{blue!25}} & multicolumn{1}{c|}{cellcolor{blue!25}} 


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

multicolumn{1}{|c|}{} & multicolumn{1}{c|}{} &  multicolumn{1}{c|}{} & multicolumn{1}{c|}{multirow{2}{*}{M}} & multicolumn{1}{c|}{multirow{2}{*}{I / PC / NLOS / M}}  &  multicolumn{1}{c|}{multirow{2}{*}{parbox{1.45cm}{NPA}}} & multicolumn{1}{c|}{} & multicolumn{1}{c|}{}  & multicolumn{1}{c|}{cellcolor{blue!25}} & multicolumn{1}{c|}{cellcolor{blue!25}} 
multicolumn{1}{|c|}{} & multicolumn{1}{c|}{} & multicolumn{1}{c|}{} & multicolumn{1}{c|}{} & multicolumn{1}{c|}{} & multicolumn{1}{c|}{} & multicolumn{1}{c|}{} & multicolumn{1}{c|}{} & multicolumn{1}{c|}{cellcolor{blue!25}} & multicolumn{1}{c|}{cellcolor{blue!25}} 

hhline{*{1}{|~}*{9}{|-}|}

multicolumn{1}{|c|}{}&multicolumn{1}{c|}{multirow{2}{*}{Cellular}} & multicolumn{2}{c|}{multirow{2}{*}{LOS}}  &  multicolumn{1}{c|}{multirow{2}{*}{I / CC / LOS}}  & multicolumn{1}{c|}{multirow{2}{*}{parbox{1.45cm}{}}}     & multicolumn{1}{c|}{} & multicolumn{1}{c|}{} & multicolumn{1}{c|}{cellcolor{blue!25}} & multicolumn{1}{c|}{cellcolor{blue!25}} 
multicolumn{1}{|c|}{} & multicolumn{1}{c|}{multirow{2}{*}{Coverage}} & multicolumn{2}{c|}{} & multicolumn{1}{c|}{} & multicolumn{1}{c|}{} & multicolumn{1}{c|}{} & multicolumn{1}{c|}{} & multicolumn{1}{c|}{cellcolor{blue!25}} & multicolumn{1}{c|}{cellcolor{blue!25}}    hhline{*{2}{|~}*{8}{|-}}


multicolumn{1}{|c|}{}&multicolumn{1}{c|}{multirow{2}{*}{$(CC)$} } & multicolumn{2}{c|}{multirow{2}{*}{NLOS}}  &  multicolumn{1}{c|}{multirow{2}{*}{I / CC / NLOS}}  & multicolumn{1}{c|}{multirow{2}{*}{parbox{1.45cm}{}}}     & multicolumn{1}{c|}{} & multicolumn{1}{c|}{} & multicolumn{1}{c|}{cellcolor{blue!25}} & multicolumn{1}{c|}{cellcolor{blue!25}} 
multicolumn{1}{|c|}{} & multicolumn{1}{c|}{} & multicolumn{2}{c|}{} & multicolumn{1}{c|}{} & multicolumn{1}{c|}{} & multicolumn{1}{c|}{} & multicolumn{1}{c|}{} & multicolumn{1}{c|}{cellcolor{blue!25}} & multicolumn{1}{c|}{cellcolor{blue!25}}   

hhline{*{10}{|-}|}
end{tabular}
}}}
end{minipage}
end{table*}

end{document}

Another problem I am facing is that when I place the table in the body of the paper, it creates a problem where vertical lines are displaced. When I isolated the code for the table to create the MWE the problem disappeared.

enter image description here

3 Answers

The reason for the misplaced vertical lines is a conflict between the arydshln and the hhline packages. You need to get rid of arydshln if you can go without it. If you can't remove arydshln, then you may try tabu, it's a powerful all-in-one tables package which can work with hhline and has its own dash-line styles.

So, in your preamble, you can use usepackage{hhline,tabu}, and to get dashed lines, just define your own style like:

newtabulinestyle{ mydashed=.5pt on 1.5pt off 1.5pt }

and use it as normal column specifiers like c, l, and r.

Correct answer by AboAmmar on September 26, 2020

off-topic but can be helpful :-): your table is unnecessary complicated ...

  • basic problem is solved by AboAmmar answer, however i suggest you don't use dashed lines in tables at all
  • in preamble you have some packages loaded twice and also three-times
  • xcolor supersede color. it is sufficient to load only xcolor
  • package subfigure is obsolete. rather use subfig or subcaption
  • there is no reason to declare all columns as m type. it is sufficient to define their width only for the first three columns, others is better to be c type. also there is no seem s to be special reason to use m{...} type. i would rather use p{...}
  • all multicolumn{1}{...}{...} are superfluous
  • use of `multirow are wrong, it is suficient to wrote their contents ones and overlaps them for each line of contents
  • exploit new options of recent version of the multirow package: {=}
  • instead center{... tcaption + table ...} is suficient to use only `centering
  • use multirow only when you cell had to span more table rows. it is not intended for make more vertical space around cells' contents. for this change arraystretch (see mwe below)
  • for coloring of cells in last two columns is more efficient to color complete columns and use colorcell only for exceptions in the first row
  • don't use scalebox ... it is desperate measure of last resort to fit table in column width

after considering above comments your table becomes:

documentclass[journal]{IEEEtran}

usepackage{amssymb, amsmath, amsthm, amsfonts}
usepackage{tabularx}
usepackage[dvips]{graphicx}% DVIPS OPTION IS SUPERFLUOUS
usepackage{epsfig}
usepackage{algorithm,algorithmic}
%usepackage{subfigure} % ABSOLETE
usepackage[table]{xcolor}% http://ctan.org/pkg/xcolor
usepackage{multirow}
usepackage{footnote}
%usepackage{arydshln}  % TROUBLEMAKER
usepackage[skip=5pt]{caption}   % Unifies the distance between caption and float
newtheorem{theorem}{Theorem}
newtheorem{definition}{Definition}
newtheorem{notation}{Notation}
newtheorem{lemma}{Lemma}
newtheorem{property}{Property}
DeclareMathOperator*{argmax}{arg,max} %Defines a new operation argmax with no space
usepackage[hyphens]{url}
usepackage{array}
usepackage{rotating}
%usepackage{color}
%usepackage{xcolor}% <-- SECOND TIME
usepackage{ragged2e}
newcolumntype{P}[1]{>{RaggedRight}p{#1}}
usepackage{cite}
bibliographystyle{IEEEtran}
usepackage{pifont}% http://ctan.org/pkg/pifont
newcommand{cmark}{ding{51}}%
newcommand{xmark}{ding{55}}%
usepackage{bm} % For bold math notations use bm{$..$}
%usepackage{arydshln} % For dashed lines. hdashline and cdashline commands which are the dashed counterparts of hline and cline
%usepackage[table]{xcolor}% <-- THIRD TIME
usepackage{hhline}
usepackage{enumitem}
%usepackage{bm} % SECOND TIME
newcommand{inchsign}{^{primeprime}}

% just for test
usepackage[floats, tightpage, active]{preview}
setlengthPreviewBorder{3mm}

begin{document}
    begin{table*}[htpb]
begin{minipage}{linewidth}% FOR FOOTNOTES BELOW TABLE?
renewcommand{thefootnote}{thempfootnote}
centering
renewcommandarraystretch{1.5}
    caption{label{tab:classification} Classification.}
begin{tabular}{|*{3}{p{1.2cm}|}
                 *{5}{c|}
                 *{2}{>{columncolor{blue!25}}c|}
                }
hhline{*{10}{|-}|}
multicolumn{5}{|c|}{Proposed Classification}
    & UShort    & Short & Medium    & cellcolor{white}{Long}
                                        & cellcolor{white}{ULong}  
hhline{*{10}{|-}|}
multirow{6}{=}{Indoor (I)}
    & multirow{4}{=}[-1ex]{Point Coverage (PC)}
        & multirow{2}{=}{LOS}
            & F & I / PC / LOS / F  &       &   &   &   &   
hhline{*{3}{|~}*{7}{|-}|}
    &   &   & M & I / PC / LOS / M  &       &   &   &   &   
hhline{*{2}{|~}*{8}{|-}|}
    &   & multirow{2}{=}{NLOS}
            & F & I / PC / NLOS / F &       &   &   &   &   
hhline{*{3}{|~}*{7}{|-}|}
    &   &   & M & I / PC / NLOS / M & NPA   &   &   &   &   
hhline{*{1}{|~}*{9}{|-}|}
    &   multirow{2}{=}{Cellular Coverage (CC)}
        & multicolumn{2}{c|}{LOS}  & I / CC / LOS  &       &   &   &   &   
hhline{*{2}{|~}*{8}{|-}}
    &   & multicolumn{2}{c|}{NLOS}  & I / CC / NLOS &       &   &   &   &   
hhline{*{10}{|-}|}
end{tabular}
end{minipage}
    end{table*}
end{document}

enter image description here

Answered by Zarko on September 26, 2020

You can easily do that with {NiceTabular} of nicematrix.

documentclass[journal]{IEEEtran}
usepackage{nicematrix}
usepackage{makecell}

begin{document}
begin{table*}[htpb]
centering
renewcommandarraystretch{1.5}
caption{label{tab:classification} Classification.}
begin{NiceTabular}{*{3}{p{1.2cm}}*{7}{c}}%
  [
    hvlines,
    code-before = rectanglecolor{blue!25}{2-9}{7-10}
  ]
Block{1-5}{Proposed Classification} & & & & 
    & UShort & Short & Medium & Long & ULong 
Block{6-1}{Indoor (I)}
    & Block{4-1}{makecell{Point Coverage (PC)}}
        & Block{2-1}{LOS}  
            & F & I / PC / LOS / F  
    &   &   & M & I / PC / LOS / M  
    &   & Block{2-1}{NLOS} 
            & F & I / PC / NLOS / F 
    &   &   & M & I / PC / NLOS / M & NPA  
    &   Block{2-1}{makecell{Cellular Coverage (CC)}}
        & Block{1-2}{LOS}  & & I / CC / LOS  
    &   & Block{1-2}{NLOS} & & I / CC / NLOS 
end{NiceTabular}
end{table*}

end{document}
  • You need several compilations.
  • In {NiceTabular}, you have a command Block to merge cells horizontally and vertically (however, blocks don't create space by themselves).
  • You have a key hvlines to draw all the rules excepted in the blocks.
  • You have commands to color cells, columns and rows. With these tools, you won't have artefacts in some PDF viewers as you have with the tools of colortbl.
  • You don't need to complete the rows with the ampersands (&) if the last cells of your rows are empty.

Output of the above code

Answered by F. Pantigny on September 26, 2020

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