以下示例显示了我的表格中的问题。左侧有一条不需要的白色规则。我该如何修复它?谢谢帮助!
\documentclass[dvipsnames,12pt]{article}
\usepackage{xcolor,array,ragged2e,booktabs,colortbl}
\usepackage{multicol,multirow} \usepackage{hhline}
\begin{document}
\newcolumntype{M}[1]{>{\hspace{0pt}\Centering $}p{#1}<{$}}
\renewcommand{\arraystretch}{1.5}
\newcommand{\vlineTS}[1][1.2pt]{\color{gray!70}\vrule width #1}
\setlength\arrayrulewidth{1.2pt}\arrayrulecolor{gray!70}%
\begin{tabular}[t]{M{1.8cm}M{1.5cm}|*{2}{M{1.5cm}|}M{1.5cm}}\hhline{*{2}{~}*{2}{|-}|~}%
& & \multicolumn{2}{!{}>{\cellcolor{cyan!20}}c!{\vlineTS}}{Merkmal II} & \\\hhline{*{2}{~}*{3}{|-}|}
& & \cellcolor{cyan!30}F & \cellcolor{cyan!30}\overline{F} &
\multicolumn{1}{!{}>{\cellcolor{Green!30}}c!{\vlineTS}}{Summe}\\\hline
\multicolumn{1}{!{\vlineTS}>{\cellcolor{cyan!30}}c!{}}{\multirow{2}*{\cellcolor{cyan!20}}} &
\multicolumn{1}{!{\vlineTS}>{\cellcolor{cyan!30}}c!{\vlineTS}}{$G$} & \cellcolor{gray!20} 0,04 &
\cellcolor{gray!20} 0,12 & \multicolumn{1}{!{}>{\cellcolor{Green!30}}c!{\vlineTS}}{$0,16$} \\\hhline{*{1}{|~}*{4}{-}}
\multicolumn{1}{!{\vlineTS}>{\cellcolor{cyan!20}}c!{}}{\raisebox{0.43cm}[0.43cm]{Merkmal I}} &
\multicolumn{1}{!{\vlineTS}>{\columncolor{cyan!30}}c!{\vlineTS}}{$\overline{G}$} &\cellcolor{gray!20} 0,36 &
\cellcolor{gray!20} 0,48 & \multicolumn{1}{!{}>{\cellcolor{Green!30}}c!{\vlineTS}}{$0,84$} \\\hline
& \multicolumn{1}{!{\vlineTS}>{\columncolor{Green!30}}c!{\vlineTS}}{Summe} &
\multicolumn{1}{!{}>{\cellcolor{Green!30}}c!{\vlineTS}}{$0,40$} &
\multicolumn{1}{!{}>{\cellcolor{Green!30}}c!{\vlineTS}}{$0,60$} &
\multicolumn{1}{!{}>{\cellcolor{Green!50}}c!{\vlineTS}}{\color{black}$1$} \\\hhline{*{1}{~}*{4}{-}}
\end{tabular}
\end{document}
答案1
\documentclass[dvipsnames,12pt]{article}
\usepackage{xcolor,array,ragged2e,booktabs,colortbl}
\usepackage{multicol,multirow} \usepackage{hhline}
\begin{document}
\newcolumntype{M}[1]{>{\hspace{0pt}\Centering $}p{#1}<{$}}
\renewcommand{\arraystretch}{1.5}
\newcommand{\vlineTS}[1][1.2pt]{\color{gray!70}\vrule width #1}
\setlength\arrayrulewidth{1.2pt}\arrayrulecolor{gray!70}%
\begin{tabular}[t]{M{1.8cm}M{1.5cm}|*{2}{M{1.5cm}|}M{1.5cm}}\hhline{*{2}{~}*{2}{|-}|~}%
& & \multicolumn{2}{!{}>{\cellcolor{cyan!20}}c!{\vlineTS}}{Merkmal II} & \\\hhline{*{2}{~}*{3}{|-}|}
& & \cellcolor{cyan!30}F & \cellcolor{cyan!30}\overline{F} &
\multicolumn{1}{!{}>{\cellcolor{Green!30}}c!{\vlineTS}}{Summe}\\\hline
\multicolumn{1}{!{\vlineTS}>{\cellcolor{cyan!30}}c!{}}{\multirow{2}*{\cellcolor{cyan!20}}} &
\multicolumn{1}{!{\vlineTS}>{\cellcolor{cyan!30}}c!{\vlineTS}}{$G$} & \cellcolor{gray!20} 0,04 &
\cellcolor{gray!20} 0,12 & \multicolumn{1}{!{}>{\cellcolor{Green!30}}c!{\vlineTS}}{$0,16$} \\
\hhline{*{1}{|>{\arrayrulecolor{cyan!20}}-}>{\arrayrulecolor{gray!70}}*{4}{-}}
\multicolumn{1}{!{\vlineTS}>{\cellcolor{cyan!20}}c!{}}{\raisebox{0.43cm}[0.43cm]{Merkmal I}} &
\multicolumn{1}{!{\vlineTS}>{\columncolor{cyan!30}}c!{\vlineTS}}{$\overline{G}$} &\cellcolor{gray!20} 0,36 &
\cellcolor{gray!20} 0,48 & \multicolumn{1}{!{}>{\cellcolor{Green!30}}c!{\vlineTS}}{$0,84$} \\\hline
& \multicolumn{1}{!{\vlineTS}>{\columncolor{Green!30}}c!{\vlineTS}}{Summe} &
\multicolumn{1}{!{}>{\cellcolor{Green!30}}c!{\vlineTS}}{$0,40$} &
\multicolumn{1}{!{}>{\cellcolor{Green!30}}c!{\vlineTS}}{$0,60$} &
\multicolumn{1}{!{}>{\cellcolor{Green!50}}c!{\vlineTS}}{\color{black}$1$} \\\hhline{*{1}{~}*{4}{-}}
\end{tabular}
\end{document}
答案2
您可以使用 轻松做到这{NiceTabular}
一点nicematrix
。
\documentclass{article}
\usepackage[dvipsnames]{xcolor}
\usepackage{nicematrix}
\begin{document}
\renewcommand{\arraystretch}{1.5}
\begin{NiceTabular}
[
corners = { NW, NE, SW } ,
hvlines ,
rules = {width=1.2pt,color = gray!70}
]
{cc*{2}{wc{1.3cm}}c}
\CodeBefore
\rectanglecolor{Green!30}{5-2}{5-4}
\rectanglecolor{Green!30}{2-5}{4-5}
\rectanglecolor{gray!20}{3-3}{4-4}
\rectanglecolor{cyan!20}{1-3}{1-4}
\rectanglecolor{cyan!20}{3-1}{4-1}
\rectanglecolor{cyan!30}{1-3}{1-4}
\rectanglecolor{cyan!30}{2-3}{2-4}
\rectanglecolor{cyan!30}{3-2}{4-2}
\cellcolor{Green!50}{5-5}
\Body
& & \Block{1-2}{Merkmal II} \\
& & $F$ & $\overline F$ & Summe \\
\Block{2-1}{Merkmal I} & $G$ & $0.04$ & $0.12$ & $0.16$ \\
& $\overline G$ & $0.36$ & $0.48$ & $0.84$ \\
& Summe & $0.40$ & $0.60$ & $1$
\end{NiceTabular}
\end{document}
您需要多次编译。
在 中
{NiceTabular}
,您可以使用命令\Block
来水平和垂直合并单元格。该键
hvlines
将绘制该键指定的块中和角落中除的所有规则corners
(此处,NW
代表西北, ETC。)。您可以使用命令来为行、单元格和列添加颜色。