彩色行和彩色單元格的頂部水平線不會出現在表格中

彩色行和彩色單元格的頂部水平線不會出現在表格中

謝謝你們。所有水平線和垂直線都會出現,但是當您為行或單元格著色時,top horizontal line disappears.這是這項工作的程式碼:

\documentclass[a4paper,11pt,twoside]{book}
\usepackage{array,multirow}
\usepackage[table]{xcolor}
\setlength{\tabcolsep}{10pt}
\setlength{\extrarowheight}{2mm}
\setlength{\arrayrulewidth}{0.2mm}
\begin{document}

   
   
\begin{tabular}{|l|*{5}{c|}}
\hline \multirow{2}{*}{Name}& \multicolumn{4}{c|}{\cellcolor{black!10} Subjects}&
\multirow{2}{*}{Total}\\
\cline{2-5} &Math & Phy & Chem & English & \\
\hline
\rowcolor{red!50}[0.98\tabcolsep] Robin & 80 & 68 & 60 & 57 & 265\\
\hline Julie & 72 & 62 & 66 & 63 & 263\\
\hline Robert & 75 & 70 & 71 & 69 & 285\\
\hline
\end{tabular}
\end{document}

這是輸出 pdf 的圖像。

在此輸入影像描述

答案1

在某些 PDF 閱讀器(例如 Adob​​e Reader)中,在某些縮放等級下,水平線會消失。

該軟體包nicematrix包含旨在避免該問題的工具。

\documentclass[a4paper,11pt,twoside]{book}
\usepackage{xcolor}
\usepackage{nicematrix}
\setlength{\tabcolsep}{10pt}
\setlength{\extrarowheight}{2mm}
\setlength{\arrayrulewidth}{0.2mm}
\begin{document}
   
\begin{NiceTabular}{l*{5}{c}}[color-inside,hvlines]
\Block{2-1}{Name}& \Block[fill=black!10]{1-4}{Subjects} &&&&
\Block{2-1}{Total}\\
&Math & Phy & Chem & English & \\
\rowcolor{red!50} Robin & 80 & 68 & 60 & 57 & 265\\
Julie & 72 & 62 & 66 & 63 & 263\\
Robert & 75 & 70 & 71 & 69 & 285\\
\end{NiceTabular}
\end{document}

您需要多次編譯(因為nicematrix在背景使用 PGF/TikZ 節點。

上述程式碼的輸出

答案2

在此輸入影像描述

\documentclass[a4paper,11pt,twoside]{book}
\usepackage{array,multirow}
\usepackage[table]{xcolor}
\setlength{\tabcolsep}{10pt}
\setlength{\extrarowheight}{2mm}
\setlength{\arrayrulewidth}{0.2mm}

\begin{document}
\begin{tabular}{|l|*{5}{c|}}
\hline 
\multirow{2}{*}{Name} & \multicolumn{4}{c|}{\cellcolor{black!10} Subjects} & \multirow{2}{*}{Total} \\
\cline{2-5} 
& Math & Phy & Chem & English & \\
\hline
\rowcolor{red!50}[0.98\tabcolsep]
Robin & 80 & 68 & 60 & 57 & 265 \\
\hline
Julie & 72 & 62 & 66 & 63 & 263 \\
\hline
Robert & 75 & 70 & 71 & 69 & 285 \\
\hline
\end{tabular}
\end{document}

相關內容