[Tex/LaTex] Horizontal line only above a multicolumn

booktabstables

I have a table in which I want a horizontal line only over a defined multicolumn. I checked some ideas from stackExchange like: How to add more space underneath and above a horizontal line in tabu? using cline or the one mentioned here: Adding a horizontal line to a multicolumn field in a longtable However, in my case the horizontal line is not appearing and I don't know why. I also tried the \cmidrule{} keyword that is mentioned here Adding table with restricted horizontal line but here I have the problem that the line is shifted to the top a bit which can be seen in the picture below.enter image description here

A small test code is attached. Any suggestion to shift the horizonal line correctly would be nice to have. Or if someone has another suggestion to achieve that. Thanks in advance. Kind regards Tobi

\documentclass[a4paper, 11pt, ngerman]{scrreprt}
\usepackage{booktabs}
\usepackage{multirow}
\usepackage{colortbl}
\usepackage{hhline}
\usepackage{xcolor}

\begin{document}
\def\arraystretch{1.15}
\begin{table}[b]
\tiny
\begin{tabular}{|c|c|c|c|c|c|c|c|c|}
 \cmidrule{6-9}
 \multicolumn{5}{c|}{} &
 \multicolumn{2}{c|}{\cellcolor{gray!10}Annahme Kugel} &
 \multicolumn{2}{c|}{\cellcolor{gray!10}Annahme Platte} 
 \\\hline
 \cellcolor{gray!10}ID & 
 \cellcolor{gray!10}Breite &  
 \cellcolor{gray!10}Länge & 
 \cellcolor{gray!10}Breite&
 \cellcolor{gray!10}Länge &
 \cellcolor{gray!10}Volumen&
 \cellcolor{gray!10}Radius (Äquiv)&
 \cellcolor{gray!10}Volumen&
 \cellcolor{gray!10}Radius (Äquiv)
 \\
 \cellcolor{gray!10}[-] &
 \cellcolor{gray!10}[px] &
 \cellcolor{gray!10}[px] &
 \cellcolor{gray!10}[$\mu$m] &
 \cellcolor{gray!10}[$\mu$m] &
 \cellcolor{gray!10}[m$^{3}$] &
 \cellcolor{gray!10}[m] &
 \cellcolor{gray!10}[m$^{3}$] &
 \cellcolor{gray!10}[m]
 \\\hhline{|=|=|=|=|=|=|=|=|=|}
1 & 22.0 & 427.6 & 2.03704E-06 & 3.95926E-05 & 1.29033E-16 & 3.13476E-06 & 3.19321E-15 & 9.13509E-06    \\
\end{tabular}
\end{table}
\end{document}

Best Answer

This a classical problem with \cline in coloured tables. The rules from booktabs do not have this problem, but they add padding above and below rules which is not coloured, whence white strips at the top and bottom of coloured rows.

The simplest solution is to use \hhline and makecell to add vertical padding at the top and bottom of cells in columns with specifiers prefixed with the letter S (or C if siunitx is loaded). To obtain this padding, one defines minimal vertical distances between a cell and the above and below cells.

So here is a possible code, in which I commented \tableSettings since I don't know how it is defined. Playing with the value of \tabcolsep, I could use \footnotesize in the place of \tiny, which is practically unreadable.

\documentclass[a4paper, 11pt, ngerman]{scrreprt}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{multirow}
\usepackage[showframe]{geometry}
\usepackage[table]{xcolor}
\usepackage{booktabs, hhline}
\usepackage{cellspace}
\setlength\cellspacetoplimit{3pt}
\setlength\cellspacebottomlimit{3pt}
\usepackage{siunitx}

\begin{document}

\begin{table}[b]
  \setlength{\tabcolsep}{2.9pt}
  \footnotesize
  \centering
  \begin{tabular}{|*{9}{Cc|}}
    \hhline{~~~~~|----|}
    \multicolumn{5}{c|}{} &
    \multicolumn{2}{Cc|}{\cellcolor{gray!10}Annahme Kugel} &
    \multicolumn{2}{Cc|}{\cellcolor{gray!10}Annahme Platte}
    \\\hline
    \rowcolor{gray!10}
    ID & Breite & Länge & {Breite} & {Länge} & {Volumen} & {Radius} & {Volumen} & {Radius}
    \\[-1.2ex]
    \rowcolor{gray!10}
    {[-]} & {[px]} & {[px]} & {[\si{\um}]} & {[\si{\um}]} & {[\si{\cubic\m}]} & {(Äquiv) [m]} & {[\si{\cubic\m}]} & { (Äquiv) [m]}
    \\\hhline{|=:=:=:=:=:=:=:=:=|}
    1 & 22.0 & 427.6 & 2.03704\,E-06 & 3.95926\,E-05 & 1.29033\,E-16 & 3.13476\,E-06 & 3.19321\,E-15 & 9.13509\,E-06 \\
  \end{tabular}
\end{table}

\end{document}

enter image description here

Related Question