2

Experimenting with the solution presented in https://tex.stackexchange.com/a/613957/144487 I find that the cells of the table are not completely filled with color:

\documentclass[12pt,
    a4paper,
    ngerman,
    numbers=noenddot, % not 1.1. but 1.1 
    oneside,
    bibliography=totocnumbered,
    listof=totoc,
    parskip=half,
]{scrreprt}

\usepackage{roboto}
\renewcommand{\familydefault}{\sfdefault}

\usepackage{tabularx}

% !!!!!!!!!!!!!!!!!!!!!
\usepackage{nicematrix}

\usepackage{booktabs} % for \midrule
\usepackage{colortbl} % in conjunction with color this creates colored tables
% Activate merged cell for tables
\usepackage{multirow}
% Fit tables etc. into page width
\usepackage{adjustbox}
% Table layout utilities
\usepackage{makecell}

\begin{document}

\begin{table}[p]
    \centering
    \caption{Some Caption}
    \label{tab:Some Caption}
    \begin{adjustbox}{max width=\textwidth}
        \begin{NiceTabular}{|l|l|c|c|c|}
            \toprule
            \textbf{Category}                   & \textbf{Core-Statement} & \textbf{Relevance}                     & \textbf{Häufigkeit}                    & \textbf{Occurrence}                   \\
            \midrule
            \multicolumn{1}{|l|}{\multirow{3}[6]{*}{Entrepreneurial Learning}}
            & Text                    & 41                                     & 37                                     & 11                                    \\
            \cmidrule{2-5}
            & More Text               & 34                                     & 31                                     & 9                                     \\
            \cmidrule{2-5}
            & Lean Startup            & 21                                     & 15                                     & 8                                     \\
            \midrule
            \multicolumn{1}{|l|}{\multirow{4}[8]{*}{Lorem Ipsum}}              & Gamma                   & 14                                     & 13                                     & 9                                     \\
            \cmidrule{2-5}                                                     & Size                    & \cellcolor[rgb]{ .906,  .902,  .902}11 & 18                                     & 11                                    \\
            \cmidrule{2-5}                                                     & Costs                   & \cellcolor[rgb]{ .906,  .902,  .902}9  & \cellcolor[rgb]{ .906,  .902,  .902}11 & \cellcolor[rgb]{ .906,  .902,  .902}6 \\
            \cmidrule{2-5}                                                     & New Stuff               & \cellcolor[rgb]{ .906,  .902,  .902}8  & \cellcolor[rgb]{ .906,  .902,  .902}9  & \cellcolor[rgb]{ .906,  .902,  .902}5 \\
            \bottomrule
        \end{NiceTabular}%
    \end{adjustbox}
    \label{tab:addlabel}%
\end{table}


\end{document}

yields

enter image description here

Any idea how to fix this?

3
  • I am not talking about the vertical rules. They are a different beast. I am asking for fixing the white gap between horizontal rules and the grey color.
    – Markus W.
    May 14, 2023 at 23:03
  • Remove the \cellcolor commands in the cells and place \CodeBefore \cellcolor[rgb]{.906,.902,.902}{6-3,7-3,8-3,8-4,7-5,8-5} \Body right after \begin{NiceTabular}{|l|l|c|c|c|}. You should probably also rather use \Blocks instead of \multirow. May 15, 2023 at 0:00
  • Note that this is not a tabular, but a NiceTabular which behaves differently in several ways. May 15, 2023 at 0:14

2 Answers 2

3

If you can accept using tabularray, then everything will become very simple.

\documentclass[12pt,a4paper,oneside,bibliography=totocnumbered,listof=totoc,parskip=half]{scrreprt}
\usepackage[sfdefault]{roboto}
\usepackage{xcolor}
\definecolor{tbgray}{rgb}{.906,.902,.902}
\usepackage{tabularray}
\begin{document}
\begin{table}[h]
\caption{title}
\begin{tblr}
{
colspec        = {*{5}{Q[co=-1,l,m]}},
row{1}         = {halign=c},
cell{2-Z}{3-Z} = {halign=c},
hlines,vlines,
row{1}         = {cmd=\bfseries},
cell{2}{1}     = {r=3}{},
cell{5}{1}     = {r=4}{},
cell{X}{3}     = {bg=tbgray},
cell{Y-Z}{3-Z} = {bg=tbgray},
}
Category                 & CoreStatement & Relevance & Häufigkeit & Occurrence \\
Entrepreneurial Learning & Text          & 41        & 37         & 11         \\
                         & More Text     & 34        & 31         & 9          \\
                         & Lean Startup  & 21        & 15         & 8          \\
Lorem Ipsum              & Gamma         & 14        & 13         & 9          \\
                         & Size          & 11        & 18         & 11         \\
                         & Costs         & 9         & 11         & 6          \\
                         & New Stuff     & 8         & 9          & 5          \\
\end{tblr}
\end{table}

\begin{table}[h]
\caption{title}
\begin{tblr}
{
colspec        = {*{5}{Q[co=-1,l,m]}},
row{1}         = {halign=c},
cell{2-Z}{3-Z} = {halign=c},
hline{1,Z}     = {wd=.08em},
hline{2,5}     = {wd=.05em},
row{1}         = {cmd=\bfseries},
cell{2}{1}     = {r=3}{},
cell{5}{1}     = {r=4}{},
cell{X}{3}     = {bg=tbgray},
cell{Y-Z}{3-Z} = {bg=tbgray},
}
Category                 & CoreStatement & Relevance & Häufigkeit & Occurrence \\
Entrepreneurial Learning & Text          & 41        & 37         & 11         \\
                         & More Text     & 34        & 31         & 9          \\
                         & Lean Startup  & 21        & 15         & 8          \\
Lorem Ipsum              & Gamma         & 14        & 13         & 9          \\
                         & Size          & 11        & 18         & 11         \\
                         & Costs         & 9         & 11         & 6          \\
                         & New Stuff     & 8         & 9          & 5          \\
\end{tblr}
\end{table}

\begin{table}[h]
\caption{title}
\begin{tblr}
{
colspec        = {*{5}{Q[co=-1,l,m]}},
row{1}         = {halign=c},
cell{2-Z}{3-Z} = {halign=c},
hline{1,Z}     = {wd=.08em},
hline{2,5}     = {wd=.05em},
row{1}         = {cmd=\bfseries},
cell{2}{1}     = {r=3}{},
cell{5}{1}     = {r=4}{},
cell{X}{3}     = {fg=red5,cmd=\bfseries},
cell{Y-Z}{3-Z} = {fg=red5,cmd=\bfseries},
}
Category                 & CoreStatement & Relevance & Häufigkeit & Occurrence \\
Entrepreneurial Learning & Text          & 41        & 37         & 11         \\
                         & More Text     & 34        & 31         & 9          \\
                         & Lean Startup  & 21        & 15         & 8          \\
Lorem Ipsum              & Gamma         & 14        & 13         & 9          \\
                         & Size          & 11        & 18         & 11         \\
                         & Costs         & 9         & 11         & 6          \\
                         & New Stuff     & 8         & 9          & 5          \\
\end{tblr}
\end{table}
\end{document}

enter image description here

1
  • Voting for the answer was hard this time, since the answer based on nicematrix is also acceptable. I still voted for this answer, because it not only respects my definitive will to have vertical lines, but also presents the alternatives without being too religious about it. Insofar this solution is more complete and deserves to be tagged as solution. Thank You, Clara.
    – Markus W.
    Jun 1, 2023 at 9:00
3

You should probably make use of the several tools the nicematrix package already provides instead of mixing different packages:

  • To solve the issue with the white gaps, remove the single \cellcolor commands in the cells and place one \cellcolor command into the \CodeBefore part of the table. This is the way to set cell colors as suggested in the package manual.

  • Also, I would probably use \Blocks instead of \multirow commands. Note that the \multicolumn commands are of no use in your code and can safely be removed anyways.

  • Finally, I would rather opt for an X column instead of scaling the table using adjustbox in order not to distort font sizes. And you should be able to remove the \centering command, since the table has full width and the caption is centered anyways.

Full MWE:

\documentclass[
    12pt,
    a4paper,
    ngerman,
    numbers=noenddot, % not 1.1. but 1.1 
    oneside,
    bibliography=totocnumbered,
    listof=totoc,
    parskip=half,
]{scrreprt}

\usepackage{roboto}
\renewcommand{\familydefault}{\sfdefault}

\usepackage{nicematrix}
\usepackage{booktabs} % for \midrule

\begin{document}

\begin{table}[p]
    \caption{Some Caption}
    \label{tab:Some Caption}
    \begin{NiceTabular}{|X[l]|l|c|c|c|}
        \CodeBefore
            \cellcolor[rgb]{.906,.902,.902}{6-3,7-3,8-3,8-4,7-5,8-5}
        \Body
            \toprule
            \textbf{Category} & \textbf{Core-Statement} & \textbf{Relevance} & \textbf{Häufigkeit} & \textbf{Occurrence}\\
            \midrule
            \Block{3-1}{Entrepreneurial Learning}
                & Text & 41 & 37 & 11 \\
            \cmidrule{2-5}
                & More Text & 34 & 31 & 9 \\
            \cmidrule{2-5}
                & Lean Startup & 21 & 15 & 8 \\
            \midrule
            \Block{4-1}{Lorem Ipsum}
                & Gamma & 14 & 13 & 9 \\
            \cmidrule{2-5} 
                & Size & 11 & 18 & 11 \\
            \cmidrule{2-5} 
                & Costs & 9 & 11 & 6 \\
            \cmidrule{2-5} 
                & New Stuff & 8 & 9 & 5 \\
            \bottomrule
    \end{NiceTabular}
    \label{tab:addlabel}
\end{table}

\end{document}

enter image description here

You must log in to answer this question.

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