multirow、colortbl 和 booktabs:使用 cellcolor 時包含 \cmidrule 和 \cline (白線)的問題

multirow、colortbl 和 booktabs:使用 cellcolor 時包含 \cmidrule 和 \cline (白線)的問題
\documentclass[12pt]{article}

\usepackage[
    a4paper,
    margin = 5mm,
    landscape,
    %showframe,
    ]
    {geometry}

\usepackage{tabularx}
\usepackage{booktabs}
\usepackage{multirow}

\renewcommand{\aboverulesep}{0pt}
\renewcommand{\belowrulesep}{0pt}

\usepackage[table]{xcolor}    % loads also colortbl
\definecolor{myTableColor}{gray}{0.80}

\usepackage[sfdefault]{cabin}

\begin{document}

\noindent
\setlength{\arrayrulewidth}{1pt}
\begin{tabularx}{\textwidth}{lc|l|X|X|X|X}
\toprule
\rowcolor{myTableColor}
\multicolumn{2}{l}{\textbf{Text}} & Text & Text & Text & Text & Text\\
\midrule
Text & \cellcolor{myTableColor} & & & & & \\
%\cmidrule{3-7}
\cline{3-7}
Text & \cellcolor{myTableColor}\multirow{-2}{*}{A} & & & & & \\
\midrule
\multicolumn{2}{l|}{Text} & & & & & \\
\midrule
Text & \cellcolor{myTableColor} & & & & & \\
\cmidrule{3-7}
%\cline{3-7}
Text & \cellcolor{myTableColor}\multirow{-2}{*}{A} & & & & & \\
\bottomrule
\end{tabularx}

% \multirow{-2}{*}{A} is taken from user Gonzalo Medina
% https://tex.stackexchange.com/questions/21155

\end{document}

在此輸入影像描述


  • 我有multirowcellcolor
  • 我想使用\cmidrule來自booktabs.
  • 我得到一條奇怪的 while 線。
  • \cline工作正常。
  • 我也嘗試過\cmidrule[0pt]
  • \cmidrule另外,和的線寬\midrule似乎不同。

答案1

此程式碼或多或少可以實現您想要的功能,makecell並且 a \Xcline{3-7}{0.05em}: 的值是( )0.05em的預設厚度。至於,預設的是。\midrule\lightrulewidth\cmidrule0.03em

\documentclass[12pt]{article}

\usepackage[
    a4paper,
    margin = 5mm,
    landscape,
    %showframe,
    ]
    {geometry}

\usepackage{tabularx}
\usepackage{booktabs, makecell}
\usepackage{multirow}

\renewcommand{\aboverulesep}{0pt}
\renewcommand{\belowrulesep}{0pt}

\usepackage[table]{xcolor} % loads also colortbl
\definecolor{myTableColor}{gray}{0.80}

\usepackage[sfdefault]{cabin}

\begin{document}

\noindent
\setlength{\arrayrulewidth}{1pt}
\begin{tabularx}{\textwidth}{lc|l|X|X|X|X}
\toprule
\rowcolor{myTableColor}
\multicolumn{2}{l}{\textbf{Text}} & Text & Text & Text & Text & Text\\
\midrule
Text & \cellcolor{myTableColor} & & & & & \\
\Xcline{3-7}{0.05em}
Text & \cellcolor{myTableColor}\multirow{-2}{*}{A} & & & & & \\
\midrule
\multicolumn{2}{l|}{Text} & & & & & \\
\midrule
Text & \cellcolor{myTableColor} & & & & & \\
\Xcline{3-7}{0.05em}
Text & \cellcolor{myTableColor}\multirow{-2}{*}{A} & & & & & \\
\bottomrule
\end{tabularx}

% \multirow{-2}{*}{A} is taken from user Gonzalo Medina
% https://tex.stackexchange.com/questions/21155

\end{document} 

在此輸入影像描述

答案2

使用{NiceTabular}of nicematrix,您可以直接使用\midruleand \cmidruleofbooktabs來獲得預期的輸出。

\documentclass[12pt]{article}
\usepackage{xcolor} 
\usepackage[a4paper,margin = 5mm,landscape]{geometry}

\usepackage{booktabs}
\renewcommand{\aboverulesep}{0pt}
\renewcommand{\belowrulesep}{0pt}

\usepackage{nicematrix}


\definecolor{myTableColor}{gray}{0.80}

\usepackage[sfdefault]{cabin}

\begin{document}

\noindent
\setlength{\arrayrulewidth}{1pt}
\begin{NiceTabularX}{\textwidth}{lc|l|X|X|X|X}
\toprule
\RowStyle[rowcolor=myTableColor]{}
\Block[l]{1-2}{\textbf{Text}} & Text & Text & Text & Text & Text \\
\midrule
Text & \Block[fill=myTableColor]{2-1}{A} & & & & & \\
\cmidrule{3-7}
Text \\
\midrule
Text \\
\midrule
Text & \Block[fill=myTableColor]{2-1}{A} & & & & & \\
\cmidrule{3-7}
Text \\
\bottomrule
\end{NiceTabularX}
    
\end{document}

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

上述程式碼的輸出

相關內容