2

enter image description hereThe following example shows the problem in my table. There is a unwanted white rule in the left. How can i fix that? Thanks for help!

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

enter image description here

\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}
1
  • Thank you very much for your quick and fantastic solution @David
    – user139826
    Jul 29 '17 at 11:47
2

You can do that easily with {NiceTabular} of 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}
  • You need several compilations.

  • In {NiceTabular}, you have the command \Block to merge cells both horizontally and vertically.

  • The key hvlines will draw all the rules excepted in the blocks and excepted in the corners specified by the key corners (here, NW stands for north-west, etc.).

  • You have commands to color rows, cells and columns.

Output of the above code

1
  • Excellent ...very very good...job.
    – Sebastiano
    Aug 4 '20 at 14:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy