TransWikia.com

Tabular and lines displaying problem with Adobe

TeX - LaTeX Asked by enigmator on July 4, 2021

Considering the following code (MWE) :

documentclass{article}
usepackage[table]{xcolor}% http://ctan.org/pkg/xcolor
begin{document}
begin{tabular}{|l|c|r|}
  hline
  Some & cellcolor{blue!25}coloured & contents 
  hline
  multicolumn{2}{|c|}{cellcolor{blue!25} multicolumn coloured} & cellcolor{blue!6} other color  hline
  Some & cellcolor{blue!15}coloured & contents 
  hline
end{tabular}
end{document}

I am having issues with tabular lines displaying, as you can notice on the following pictures.


With Evince (LINUX) :

Linux displays

No problem so far.


With Adobe (WINDOWS) :

windows display

As you can see, lines are not displayed properly.

How can I fix this problem ? I wish my document would be displayable whatever the operating system.


NOTES :

  • I tried to follow this post proposal link, but unfortunately, it didn’t fixed the problem.
  • I compile on Linux with pdflatex, version 3.1415926-2.5-1.40.14 (TeX Live 2013/Debian)
  • That’s the same issue with no multicolumn as you can see on below :
    with no multicolumn, windows

2 Answers

A quite crude workaround is to set the table twice, the second time without background colors. Also the rule thickness can be increased by setting arrayrulewidth:

documentclass{article}
usepackage{array}
usepackage[table]{xcolor}% http://ctan.org/pkg/xcolor
begin{document}

setlength{arrayrulewidth}{1.5arrayrulewidth}% 50% thicker
deftmp{%
  begin{tabular}{|l|c|r|}
    hline
    Some & cellcolor{blue!25}coloured & contents 
    hline
    multicolumn{2}{|c|}{cellcolor{blue!25}multicolumn coloured} &
    cellcolor{blue!6}other color  hline
    Some & cellcolor{blue!15}coloured & contents 
    hline
  end{tabular}%
}
leavevmode
rlap{tmp}%
begingroup
  renewcommand*{cellcolor}[1]{}%
  tmp
endgroup
end{document}

Result

Remarks:

  • LaTeX removes spaces at the begin and end of a cell. But the space after cellcolor{...} is inside the cell and is not automatically removed.

Automation

The procedure can be automated to some degree. The following example at least supports column types l, c, r, p, m, b. Internals are redefined to catch the cell contents in boxes and to replace them with empty boxes of the same dimensions.

Unsupported are text inside @{...}, longtable, ...

documentclass{article}
usepackage{array}
usepackage[table]{xcolor}% http://ctan.org/pkg/xcolor

makeatletter
letorg@insert@columninsert@column
newcommand*{dummy@insert@column@h}{%
  begingroup
    setbox0=hboxbgroupbegingroup
      org@insert@column
    endgroupegroup
    setbox2=hbox{}%
    wd2=wd0 %
    ht2=ht0 %
    dp2=dp0 %
    copy2 %
  endgroup
}
newcommand*{dummy@endpbox}{%
  @finalstrut@arstrutbox
  egroup
  begingroup
    setbox0=lastbox
    setbox2=hbox{}%
    wd2=wd0 %
    ht2=ht0 %
    dp2=dp0 %
    copy2 %
  endgroup
  hfil
}
newcommand*{dummy@classz}{%
  @classx
  @tempcnta count@
  prepnext@tok
  @addtopreamble{%
    ifcase @chnum
      hfil d@llarbegin
      dummy@insert@column@h
      d@llarend hfil
    or
      hskip1spd@llarbegin
      dummy@insert@column@h
      d@llarend hfil
    or
      hfilhskip1spd@llarbegin
      dummy@insert@column@h
      d@llarend
    or
      $vcenter
      @startpbox{@nextchar}insert@column dummy@endpbox
      $%
    or
      vtop
      @startpbox{@nextchar}insert@column dummy@endpbox
    or
      vbox
      @startpbox{@nextchar}insert@column dummy@endpbox
    fi
  }%
  prepnext@tok
}
newcommand*{tabulardummysetup}{%
  renewcommand*{cellcolor}[1]{null}%
  let@classzdummy@classz
}
newcommand{tabularfix}[1]{%
  deftabularfix@contents{ignorespaces#1ifhmodeunskipfi}%
  leavevmode
  rlap{tabularfix@contents}%
  begingroup
    tabulardummysetup
    tabularfix@contents
  endgroup
}
makeatother

setlength{arrayrulewidth}{1.5arrayrulewidth}

begin{document}

tabularfix{%
  begin{tabular}[t]{|l|c|r|}
    hline
    Some & cellcolor{blue!25}coloured & contents 
    hline
    multicolumn{2}{|c|}{cellcolor{blue!25}multicolumn coloured} &
    cellcolor{blue!6}other color  hline
    Some & cellcolor{blue!15}coloured & multicolumn{1}{p{20mm}|}{contents} 
    hline
  end{tabular}%
}

bigskip

begingroup
  tabulardummysetup
  begin{tabular}{|l|c|r|}
    hline
    Some & cellcolor{blue!25}coloured & contents 
    hline
    multicolumn{2}{|@{kerntabcolsep}c|}{cellcolor{blue!25}multicolumn coloured} &
    cellcolor{blue!6}other color  hline
    Some & cellcolor{blue!15}coloured & multicolumn{1}{p{20mm}|}{contents} 
    hline
  end{tabular}%
endgroup

end{document}

Result

Correct answer by Heiko Oberdiek on July 4, 2021

The package nicematrix has tools designed to address that problem. With the environment {NiceTabular} of that package, the rules won't disappear because the colored panels are drawn before the rules (with informations written previously on the aux file: that's why you need several compilations).

documentclass{article}
usepackage{nicematrix}
begin{document}
begin{NiceTabular}{lcr}[colortbl-like,hvlines]
  Some & cellcolor{blue!25}coloured & contents 
  Block[fill=blue!25]{1-2}{multicolumn} & & cellcolor{blue!6}other color  
  Some & cellcolor{blue!15}coloured & contents 
end{NiceTabular}
end{document}

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

Output of the above code

If you prefer, it's also possible to specify the formatting instructions outside the main array (the output is the same).

documentclass{article}
usepackage{nicematrix}
begin{document}
begin{NiceTabular}{lcr}[hvlines]
CodeBefore
cellcolor{blue!25}{1-2,2-1,2-2,3-2}
cellcolor{blue!6}{2-3}
Body
  Some        & coloured & contents 
  Block{1-2}{multicolumn} & & other color  
  Some        & coloured & contents 
end{NiceTabular}
end{document}

Answered by F. Pantigny on July 4, 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