1

I don't understand why some lines do not render in my table when cells are colored (using tabular).

Line should be black

The lines are visible but not completly and they are not black (they seem to be overlayed by the cell color)

Here is a MWE:

\documentclass{article}

\usepackage{ifxetex}
\usepackage{eurosym}
\ifxetex
    \usepackage{fontspec}
    \usepackage{xunicode}
    \usepackage{xltxtra}

    \usepackage{polyglossia}
    \setdefaultlanguage{french}
    \defaultfontfeatures{Ligatures=TeX} 

\else
    \usepackage[T1]{fontenc}
    \usepackage[utf8]{inputenc}
    \usepackage[french]{babel}
    \usepackage{mathptmx} %Times new roman
    \hypersetup{pdftex, colorlinks=true, linkcolor=blue, citecolor=blue, filecolor=blue, urlcolor=blue, pdftitle= }
    \usepackage[pdftex]{graphicx}
\fi

\usepackage{color}
\usepackage{supertabular}
\makeatletter
\newcommand\arraybslash{\let\\\@arraycr}
\makeatother
\setlength\tabcolsep{1mm}
\title{ }
\usepackage{multirow}
\usepackage{colortbl}
\newcolumntype{L}[1]{>{\raggedright\let\newline\\\arraybackslash\hspace{1pt}}m{#1}}
\newcolumntype{C}[1]{>{\centering\let\newline\\\arraybackslash\hspace{1pt}}m{#1}}
\newcolumntype{R}[1]{>{\raggedleft\let\newline\\\arraybackslash\hspace{1pt}}m{#1}}

\usepackage[many]{tcolorbox}
\definecolor{griscellule}{HTML}{D9D9D9}

\begin{document}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Les dimensions du tableau
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\newdimen\colBase
\colBase=0.9\columnwidth

\newdimen\colA
\colA=0.3\colBase

\newdimen\colB
\colB=0.25\colBase

\newdimen\colC
\colC=0.22\colBase

\newdimen\colD
\colD=0.23\colBase

\newdimen\colBscA
\newdimen\colBscB
\newdimen\colBscC   
\colBscA=0.4\colB
\colBscB=0.2\colB
\colBscC=0.4\colB

\newdimen\colDscA
\colDscA=0.16\colD

\newdimen\colDscB
\colDscB=0.84\colD

\newdimen\colBCD
\colBCD=\colB
\addtolength{\colBCD}{\colC}
\addtolength{\colBCD}{\colD}

\newdimen\colContenu
\colContenu=\colA
\addtolength{\colContenu}{\colB}
\addtolength{\colContenu}{\colC}
\addtolength{\colContenu}{\colDscA}

\newcommand{\titreChamp}{\small\bfseries}
\newcommand{\celluleGrise}{\cellcolor{griscellule}}
\renewcommand\arraystretch{0.95}


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{flushleft}
\begin{tabular}{|m{\colA}m{\colBscA}m{\colBscB}m{\colBscC}m{\colC}|m{\colDscA}m{\colDscB}|}
\hline
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\multicolumn{1}{|m{\colA}|}{\celluleGrise\raggedleft{\titreChamp There should be a line below :}} &
\multicolumn{3}{m{\colB}|}{\small The Name is} &
\celluleGrise &
\multicolumn{2}{m{\colD}|}{\multirow{2}{\colD}{~}}\\\cline{1-4}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\multicolumn{1}{|m{\colA}|}{\celluleGrise\raggedleft\titreChamp There should be line above : } &
\multicolumn{3}{m{\colB}|}{\small 02/02/2020} &
\multicolumn{1}{m{\colC}|}{
    \raisebox{1.6ex}[2.0ex]{\multirow{-2}{\colC}{\celluleGrise\raggedleft{\titreChamp Multirow title :}}}
} %
& & %
\raisebox{1.4ex}[2.7ex]{\multirow{-2}{0.1ex}{multirow value}} %
\\\cline{1-5}%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\multicolumn{1}{|m{\colA}|}{\celluleGrise\raggedleft\titreChamp There should be line above : } &
\multicolumn{3}{m{\colB}|}{\small blank} &
\multicolumn{1}{m{\colC}|}{\celluleGrise\raggedleft{ No line above }} %
& & %
\raisebox{1.4ex}[2.7ex]{a value} %
\\\cline{1-5}%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\multicolumn{1}{|m{\colA}|}{\raggedleft\titreChamp There is line above : } &
\multicolumn{3}{m{\colB}|}{\small blank} &
\multicolumn{1}{m{\colC}|}{\raggedleft{ A line above }} %
& & %
\raisebox{1.4ex}[2.7ex]{a value} %
\\\hline
\end{tabular}
\end{flushleft}
\end{document}

I am using pdflatex and xelatex on macOS

Is there a solution to make my horizontal lines render correctly ?

1

2 Answers 2

2

I don't know exactly why either, but this a well-known problem. An elementary solution uses the hhline package. I took the opportunity to simplify a bit your code – loading xcolor with option [table] rather than color+colortbl. Also replaced the multiple calls to \celluleGrise\raggedleft with >{\columncolor{griscellule}\raggedleft} in the table preamble, and a \rowcolor{white} at the very beginning of the last row.

    \documentclass{article}

    \usepackage{ifxetex}
    \usepackage{eurosym}
    \ifxetex
        \usepackage{fontspec}
        \usepackage{xunicode}
        \usepackage{xltxtra}

        \usepackage{polyglossia}
        \setdefaultlanguage{french}
        \defaultfontfeatures{Ligatures=TeX}

    \else
        \usepackage[T1]{fontenc}
        \usepackage[utf8]{inputenc}
        \usepackage[french]{babel}
        \usepackage{mathptmx} %Times new roman
        \usepackage[pdftex]{graphicx}
    \fi

    \usepackage[table]{xcolor}
    \usepackage{supertabular}
    \makeatletter
    \newcommand\arraybslash{\let\\\@arraycr}
    \makeatother
    \setlength\tabcolsep{1mm}
    \title{ }
    \usepackage{multirow}
    \newcolumntype{L}[1]{>{\raggedright\let\newline\\\arraybackslash\hspace{1pt}}m{#1}}
    \newcolumntype{C}[1]{>{\centering\let\newline\\\arraybackslash\hspace{1pt}}m{#1}}
    \newcolumntype{R}[1]{>{\raggedleft\let\newline\\\arraybackslash\hspace{1pt}}m{#1}}

    \usepackage[many]{tcolorbox}
    \definecolor{griscellule}{HTML}{D9D9D9}
    \usepackage{hhline}
    \usepackage{hyperref}
        \hypersetup{pdftex, colorlinks=true, linkcolor=blue, citecolor=blue, filecolor=blue, urlcolor=blue, pdftitle= }

    \begin{document}
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    % Les dimensions du tableau
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    \newdimen\colBase
    \colBase=0.9\columnwidth

    \newdimen\colA
    \colA=0.3\colBase

    \newdimen\colB
    \colB=0.25\colBase

    \newdimen\colC
    \colC=0.22\colBase

    \newdimen\colD
    \colD=0.23\colBase

    \newdimen\colBscA
    \newdimen\colBscB
    \newdimen\colBscC
    \colBscA=0.4\colB
    \colBscB=0.2\colB
    \colBscC=0.4\colB

    \newdimen\colDscA
    \colDscA=0.16\colD

    \newdimen\colDscB
    \colDscB=0.84\colD

    \newdimen\colBCD
    \colBCD=\colB
    \addtolength{\colBCD}{\colC}
    \addtolength{\colBCD}{\colD}

    \newdimen\colContenu
    \colContenu=\colA
    \addtolength{\colContenu}{\colB}
    \addtolength{\colContenu}{\colC}
    \addtolength{\colContenu}{\colDscA}

    \newcommand{\titreChamp}{\small\bfseries}
    \newcommand{\celluleGrise}{\cellcolor{griscellule}}
    \renewcommand\arraystretch{0.95}

    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    \begin{flushleft}
    \begin{tabular}{|>{\columncolor{griscellule}\raggedleft}m{\colA}|m{\colBscA}m{\colBscB}m{\colBscC}m{\colC}|m{\colDscA}m{\colDscB}|}
    \hline
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    \raggedleft{\titreChamp There should be a line below :} &
    \multicolumn{3}{m{\colB}|}{\small The Name is} &
    \celluleGrise &
    \multicolumn{2}{m{\colD}|}{\multirow{2}{\colD}{~}}\\%
    \noalign{\vskip-0.5pt}
    \hhline{---->{\arrayrulecolor{griscellule}}->{\arrayrulecolor{black}}|~~|}
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    \titreChamp There should be a line above : &
    \multicolumn{3}{m{\colB}|}{\small 02/02/2020} &
    \multicolumn{1}{m{\colC}|}{
        \raisebox{1.6ex}[2.0ex]{\multirow{-2}{\colC}{\celluleGrise\raggedleft{\titreChamp Multirow title :}}}
    } %
    & & %
    \raisebox{1.4ex}[2.7ex]{\multirow{-2}{0.1ex}{multirow value}} %
    \\%
    \noalign{\vskip-0.4pt}
    \hhline{---->{\arrayrulecolor{griscellule}}->{\arrayrulecolor{black}}|~~|}
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    \titreChamp There should be a line above : &
    \multicolumn{3}{m{\colB}|}{\small blank} &
    \multicolumn{1}{m{\colC}|}{\celluleGrise\raggedleft{ No line above }} %
    & & %
    \raisebox{1.4ex}[2.7ex]{a value} %
    \\
    \hhline{-----|~~|}
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    \rowcolor{white}\titreChamp There is a line above : &
    \multicolumn{3}{m{\colB}|}{\small blank} &
    \multicolumn{1}{m{\colC}|}{\raggedleft{A line above }} %
    & & %
    \raisebox{1.4ex}[2.7ex]{a value} %
    \\\hline
    \end{tabular}
    \end{flushleft}

    \end{document}

enter image description here

0

In {tabular} (of standard LaTeX and also with the package array), the rules specified by the command \cline protude in the cells which are on the following row. That's a sensible difference with the command \hline since a rule drawn by \hline spreads the rows.

As a consequence, if there is a colored cell below a \cline, the colored panel of that cell overlaps the \cline (usually, we still see a thin rule in the PDF viewer but this is an artefact of the PDF viewer).

In {NiceTabular} of nicematrix, the command \cline has been redefined to spread the rows, as does \hline.

The package nicematrix has also been designed to generate PDF which avoid some frequent artefacts in the PDF viewers with colored tabulars constructed with the classical package colortbl.

\documentclass{article}

\usepackage{ifxetex}
\usepackage{eurosym}
\ifxetex
    \usepackage{fontspec}
    \usepackage{xunicode}
    \usepackage{xltxtra}

    \usepackage{polyglossia}
    \setdefaultlanguage{french}
    \defaultfontfeatures{Ligatures=TeX}

\else
    \usepackage[T1]{fontenc}
    \usepackage[utf8]{inputenc}
    \usepackage[french]{babel}
    \usepackage{mathptmx} %Times new roman
    \usepackage[pdftex]{graphicx}
\fi

\usepackage[table]{xcolor}
\usepackage{supertabular}
\makeatletter
\newcommand\arraybslash{\let\\\@arraycr}
\makeatother
\setlength\tabcolsep{1mm}
\title{ }
\usepackage{multirow}
\newcolumntype{L}[1]{>{\raggedright\let\newline\\\arraybackslash\hspace{1pt}}m{#1}}
\newcolumntype{C}[1]{>{\centering\let\newline\\\arraybackslash\hspace{1pt}}m{#1}}
\newcolumntype{R}[1]{>{\raggedleft\let\newline\\\arraybackslash\hspace{1pt}}m{#1}}

\definecolor{griscellule}{HTML}{D9D9D9}
\usepackage{hyperref}
    \hypersetup{pdftex, colorlinks=true, linkcolor=blue, citecolor=blue, filecolor=blue, urlcolor=blue, pdftitle= }

\usepackage{nicematrix}

\begin{document}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Les dimensions du tableau
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\newdimen\colBase
\colBase=0.9\columnwidth

\newdimen\colA
\colA=0.3\colBase

\newdimen\colB
\colB=0.25\colBase

\newdimen\colC
\colC=0.22\colBase

\newdimen\colD
\colD=0.23\colBase

\newdimen\colBscA
\newdimen\colBscB
\newdimen\colBscC
\colBscA=0.4\colB
\colBscB=0.2\colB
\colBscC=0.4\colB

\newdimen\colDscA
\colDscA=0.16\colD

\newdimen\colDscB
\colDscB=0.84\colD

\newdimen\colBCD
\colBCD=\colB
\addtolength{\colBCD}{\colC}
\addtolength{\colBCD}{\colD}

\newdimen\colContenu
\colContenu=\colA
\addtolength{\colContenu}{\colB}
\addtolength{\colContenu}{\colC}
\addtolength{\colContenu}{\colDscA}

\newcommand{\titreChamp}{\small\bfseries}

\renewcommand\arraystretch{0.95}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{flushleft}
\begin{NiceTabular}{>{\raggedleft}m{\colA}m{\colBscA}m{\colBscB}m{\colBscC}m{\colC}m{\colDscA}m{\colDscB}}[hvlines]
\CodeBefore
  \rectanglecolor{griscellule}{1-1}{3-1}
\Body
\raggedleft \titreChamp There should be a line below : &
\multicolumn{3}{m{\colB}}{\small The Name is} &
\Block[fill=griscellule]{3-1}{} & \Block{*-2}{} \\%
\noalign{\vskip-0.5pt}
\titreChamp There should be a line above : &
\multicolumn{3}{m{\colB}}{\small 02/02/2020} &
\multicolumn{1}{m{\colC}}{
    \raisebox{1.6ex}[2.0ex]{\multirow{-2}{\colC}{\raggedleft \titreChamp Multirow title :}}} 
& & 
\raisebox{1.4ex}[2.7ex]{\multirow{-2}{0.1ex}{multirow value}} 
\\
\noalign{\vskip-0.4pt}
\titreChamp There should be a line above : &
\multicolumn{3}{m{\colB}}{\small blank} &
\multicolumn{1}{m{\colC}}{\raggedleft No line above} 
& & 
\raisebox{1.4ex}[2.7ex]{a value} 
\\
\titreChamp There is a line above : &
\multicolumn{3}{m{\colB}}{\small blank} &
\multicolumn{1}{m{\colC}}{\raggedleft A line above} 
& & %
\raisebox{1.4ex}[2.7ex]{a value} 
\end{NiceTabular}
\end{flushleft}

\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 .