4

I have a problem with coloring a cell in a table because it removes the upper line of the cell. I already found out that there are some issues with \cellcolor and \cline but I couldn't come up with a solution that works with \multicolumn.

\documentclass{article}
\usepackage{amsmath}
\usepackage{multirow}
\usepackage{multicol}
\usepackage{rotating}       
\usepackage[table]{xcolor}  
\usepackage{siunitx}        

\begin{document}
    \begin{tabular}{|c|c|c|c|c|c|}
        \cline{3-6}
        \multicolumn{2}{c|}{} & \multicolumn{4}{c|}{Anzahl der Nullstellen} \\
        \cline{3-6}
        \multicolumn{2}{c|}{} & 0 & 1 & 2 & 3 \\
        \hline
        \multirow{18}{*}{\rotatebox[origin=c]{90}{Anzahl der Polstellen}} & 1 & $\begin{matrix} \SI{99.9}{\percent} \\ \SI{37.7}{\percent} \\ \SI{43.8}{\percent} \\ \SI{45.1}{\percent}\end{matrix}$ & $\begin{matrix} \SI{99.9}{\percent} \\ \SI{41.5}{\percent} \\ \SI{67.5}{\percent} \\ \SI{72.6}{\percent}\end{matrix}$ & \multicolumn{2}{c|}{} \\
        \cline{2-5}
        & 2 & $\begin{matrix} \SI{99.9}{\percent} \\ \SI{72}{\percent} \\ \SI{78.4}{\percent} \\ \SI{77.8}{\percent}\end{matrix}$ & $\begin{matrix} \SI{99.9}{\percent} \\ \SI{72.6}{\percent} \\ \SI{92.5}{\percent} \\ \SI{94.4}{\percent}\end{matrix}$ & $\begin{matrix} \SI{99.5}{\percent} \\ \SI{72.7}{\percent} \\ \SI{97.2}{\percent} \\ \SI{98.3}{\percent}\end{matrix}$ &  \\
        \cline{2-6}
        & 3 & $\begin{matrix} \SI{98.6}{\percent} \\ \SI{-42.7}{\percent} \\ \SI{95.7}{\percent} \\ \SI{94.2}{\percent}\end{matrix}$ & {\cellcolor{black!25}} $\begin{matrix} \SI{99.9}{\percent} \\ \SI{73.4}{\percent} \\ \SI{99.1}{\percent} \\ \SI{99.3}{\percent}\end{matrix}$ & $\begin{matrix} \SI{99.9}{\percent} \\ \SI{-40.1}{\percent} \\ \SI{99.3}{\percent} \\ \SI{96.7}{\percent}\end{matrix}$ & $\begin{matrix} \SI{99.7}{\percent} \\ \SI{72.8}{\percent} \\ \SI{99.4}{\percent} \\ \SI{98}{\percent}\end{matrix}$ \\
        \cline{2-6}
        & 4 & $\begin{matrix} \SI{0}{\percent} \\ \SI{67.8}{\percent} \\ \SI{93.2}{\percent} \\ \SI{93}{\percent}\end{matrix}$ & $\begin{matrix} \SI{99.5}{\percent} \\ \SI{-23.5}{\percent} \\ \SI{95.4}{\percent} \\ \SI{93}{\percent}\end{matrix}$ & $\begin{matrix} \SI{99.9}{\percent} \\ \SI{73.9}{\percent} \\ \SI{5.3}{\percent} \\ \SI{93}{\percent}\end{matrix}$ & $\begin{matrix} \SI{99.9}{\percent} \\ \SI{74}{\percent} \\ \SI{-87.1}{\percent} \\ \SI{96.5}{\percent}\end{matrix}$ \\
        \cline{2-6}
        & 5 & $\begin{matrix} \SI{-99.7}{\percent} \\ \SI{-82.9}{\percent} \\ \SI{-99.4}{\percent} \\ \SI{93}{\percent}\end{matrix}$ & $\begin{matrix} \SI{-99.8}{\percent} \\ \SI{64.9}{\percent} \\ \SI{2.7}{\percent} \\ \SI{93}{\percent}\end{matrix}$ & $\begin{matrix} \SI{-100.5}{\percent} \\ \SI{-69.8}{\percent} \\ \SI{59.1}{\percent} \\ \SI{93}{\percent}\end{matrix}$ & $\begin{matrix} \SI{-0.4}{\percent} \\ \SI{73.9}{\percent} \\ \SI{14.4}{\percent} \\ \SI{93.1}{\percent}\end{matrix}$ \\
        \hline
    \end{tabular}
\end{document}

Here is the Problem

Btw can somebody tell me why I had to put 18 in \multirow?

2
  • 3
    Using \hhline as usually recommended in connection with \cellcolor should also work in your case. (\hhline{|~|-|-|-|-|-|})
    – leandriis
    Mar 8, 2019 at 20:55
  • Thank you, this worked for me. I tried it already before but did something wrong.
    – Kaniee
    Mar 8, 2019 at 21:08

1 Answer 1

3

As @leandris has kindly suggested in a comment, to make sure that the horizontal line shows up fully, it suffices to (a) load the hhline package and (b) replace the \cline{3-6} directive in question with \hhline{~~----}.

In addition, you may want to simplify your code considerably. For instance, by employing an array environment instead of a tabular environment, you can get rid of all $ symbols. There's no real discernible need for encasing the percentage numbers in \SI{...}{...} wrappers.

(The "missing" vertical line to the left of the shaded cell is an artifact of the low resolution of the screenshot; in a normal pdf file it'll show up just fine.)

enter image description here

\documentclass{article}
\usepackage{mathtools,hhline}
\usepackage{multirow}
\usepackage{rotating}       
\usepackage[table]{xcolor}    
\usepackage{siunitx}        

\begin{document}
\[
\setlength\extrarowheight{1pt}
\begin{array}{|*{6}{c|}}
\cline{3-6}
\multicolumn{2}{c|}{} 
& \multicolumn{4}{c|}{\text{Anzahl der Nullstellen}} \\
\cline{3-6}
\multicolumn{2}{c|}{} & 0 & 1 & 2 & 3 \\
\hline
\multirow{17}{*}{\rotatebox[origin=c]{90}{Anzahl der Polstellen}} 
& 1 
& \begin{matrix*}[r] \phantom{-}99.9\% \\ 37.7\% \\ 43.8\% \\ 45.1\%\end{matrix*} 
& \begin{matrix*}[r] \phantom{-}99.9\% \\ 41.5\% \\ 67.5\% \\ 72.6\%\end{matrix*} 
& \multicolumn{2}{c|}{} \\
\cline{2-5}    
& 2 
& \begin{matrix*}[r] \phantom{-}99.9\% \\ 72.0\% \\ 78.4\% \\ 77.8\%\end{matrix*} 
& \begin{matrix*}[r] \phantom{-}99.9\% \\ 72.6\% \\ 92.5\% \\ 94.4\%\end{matrix*} 
& \begin{matrix*}[r] \phantom{-1}99.5\% \\ 72.7\% \\ 97.2\% \\ 98.3\%\end{matrix*} 
&  \\
%\cline{2-6}
\hhline{~~----}
& 3 
& \begin{matrix*}[r] 98.6\% \\ -42.7\% \\ 95.7\% \\ 94.2\%\end{matrix*} 
& \cellcolor{black!12} 
  \begin{matrix*}[r] \phantom{-}99.9\% \\ 73.4\% \\ 99.1\% \\ 99.3\%\end{matrix*} 
& \begin{matrix*}[r] \phantom{-1}99.9\% \\ -40.1\% \\ 99.3\% \\ 96.7\%\end{matrix*} 
& \begin{matrix*}[r] \phantom{-}99.7\% \\ 72.8\% \\ 99.4\% \\ 98\%\end{matrix*} \\
\cline{2-6}
& 4 
& \begin{matrix*}[r] 0.0\% \\ \phantom{-}67.8\% \\ 93.2\% \\ 93.0\%\end{matrix*} 
& \begin{matrix*}[r] 99.5\% \\ -23.5\% \\ 95.4\% \\ 93.0\%\end{matrix*} 
& \begin{matrix*}[r] \phantom{-1}99.9\% \\ 73.9\% \\ 5.3\% \\ 93.0\%\end{matrix*} 
& \begin{matrix*}[r] 99.9\% \\ 74\% \\ -87.1\% \\ 96.5\%\end{matrix*} \\
\cline{2-6}
& 5 
& \begin{matrix*}[r] -99.7\% \\ -82.9\% \\ -99.4\% \\ 93.0\%\end{matrix*} 
& \begin{matrix*}[r] -99.8\% \\ 64.9\% \\ 2.7\% \\ 93.0\%\end{matrix*} 
& \begin{matrix*}[r] -100.5\% \\ -69.8\% \\ 59.1\% \\ 93.0\%\end{matrix*} 
& \begin{matrix*}[r] -0.4\% \\ 73.9\% \\ 14.4\% \\ \phantom{-}93.1\%\end{matrix*} \\
\hline
\end{array}
\]
\end{document}
11
  • 1
    The problem is still the same with this code. Only the color is darker.
    – Kaniee
    Mar 8, 2019 at 21:04
  • 1
    @Sebastiano: Using \hhline will fix the problem.
    – leandriis
    Mar 8, 2019 at 21:05
  • 2
    Replace \cline{2-6} by \hhline{|~|-|-|-|-|-|} and load the hline package.
    – leandriis
    Mar 8, 2019 at 21:11
  • 1
    I've edited your code to implement @leadris's keen suggestion, and also to streamline some of other code provided by the OP. Feel free to revert.
    – Mico
    Mar 8, 2019 at 21:18
  • 1
    @Sebastiano: booktabs does not cooperate very well with vertical lines, so, although I personally use booktabs quite often, this package is most likely not applicable to this specific question.
    – leandriis
    Mar 8, 2019 at 21:24

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .