为什么这些彩色单元格不能正确呈现线条?

为什么这些彩色单元格不能正确呈现线条?

我不明白为什么当单元格被着色(使用表格)时某些线条不会在我的表格中呈现。

线应该是黑色的

线条可见但不完整,并且不是黑色(它们似乎被单元格颜色覆盖)

以下是 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}

我在 macOS 上使用 pdflatex 和 xelatex

有什么解决方案可以使我的水平线正确呈现吗?

答案1

我也不知道具体原因,但这是一个众所周知的问题。一个基本的解决方案是使用 hhline包。我借此机会简化了你的代码——xcolor使用 option[table] 而不是color+加载。还替换了表格前言中对with 的colortbl多次调用,以及最后一行开头的 a。\celluleGrise\raggedleft>{\columncolor{griscellule}\raggedleft}\rowcolor{white}

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

在此处输入图片描述

答案2

{tabular}(标准 LaTeX 和包中array)中,命令指定的规则\cline在下一行单元格中突出。这与命令有明显的区别,\hline因为由绘制的规则\hline会展开行。

因此,如果 在 下方有一个彩色单元格\cline,则该单元格的彩色面板会与其重叠\cline(通常,我们仍然会在 PDF 查看器中看到一条细线,但这是 PDF 查看器的产物)。

{NiceTabular}nicematrix,命令\cline已被重新定义为展开行,就像 一样\hline

该包nicematrix还被设计用于生成 PDF,从而避免使用经典包构建的彩色表格在 PDF 查看器中经常出现的一些伪影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}

您需要多次编译(因为nicematrix在后台使用 PGF/Tikz 节点)。

上述代码的输出

相关内容