![\cellcolor 颜色填充 \tabular 中用 cmidrule 分隔的单元格有垂直间隙](https://linux22.com/image/464747/%5Ccellcolor%20%E9%A2%9C%E8%89%B2%E5%A1%AB%E5%85%85%20%5Ctabular%20%E4%B8%AD%E7%94%A8%20cmidrule%20%E5%88%86%E9%9A%94%E7%9A%84%E5%8D%95%E5%85%83%E6%A0%BC%E6%9C%89%E5%9E%82%E7%9B%B4%E9%97%B4%E9%9A%99.png)
尝试使用https://tex.stackexchange.com/a/613957/144487我发现表格的单元格没有完全填充颜色:
\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}
产量
知道如何修复这个问题吗?
答案1
如果你能接受使用tabularray
,那么一切都会变得非常简单。
\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}
答案2
您可能应该使用该nicematrix
软件包已经提供的几种工具,而不是混合使用不同的软件包:
要解决白色间隙的问题,请删除
\cellcolor
单元格中的单个命令,然后将一个\cellcolor
命令放入\CodeBefore
表格部分。这是设置单元格颜色的方法,如包装手册。另外,我可能会使用
\Block
s 而不是\multirow
命令。请注意,这些\multicolumn
命令在您的代码中毫无用处,无论如何都可以安全地删除。最后,为了不扭曲字体大小,我宁愿选择一
X
列而不是使用缩放表格。而且您应该能够删除该命令,因为表格具有全宽并且标题无论如何都是居中的。adjustbox
\centering
完整 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}