在下表中,当我根据需要设置行高、列宽和缩进时,行的颜色会中断,留下一些“未着色”区域(见示例)。我该如何解决这个问题(同时保持行高和缩进)?
在此先谢谢大家的帮助!PS svmono 类可以下载这里。
例子:
\documentclass[graybox,envcountchap,vecarrow,twoside]{svmono}
\usepackage[paperheight=240mm,paperwidth=170mm,top=2.5cm,inner=2.5cm]{geometry}
\usepackage{newtxtext}
\usepackage{newtxmath}
% Units
\usepackage[detect-weight=true,detect-family=true,per-mode=symbol,detect-all=true]{siunitx}
% Tables
\usepackage{booktabs}
\usepackage{multirow}
\usepackage{multicol}
\usepackage{makecell}
\usepackage{xcolor,colortbl}
\definecolor{cellHighlightColor}{rgb}{0.933333333333333 0.956862745098039 0.984313725490196}
\renewcommand{\arraystretch}{1.2}
\begin{document}
\begin{table}[!ht]
\centering
\caption{Predicted occurrence of technological ``tipping points''}
\begin{small}
\begin{tabular}{@{\hspace{6pt}}p{1.25cm}p{9cm}}
\toprule
Year& \multicolumn{1}{c}{Technological tipping points}\\
\midrule
\rowcolor{cellHighlightColor}2022& 1 trillion sensors connected to the internet\\%S08
\rowcolor{cellHighlightColor}& \SI{10}{\percent} of people wearing clothes connected to the internet\\%S04
\rowcolor{cellHighlightColor}& The first 3D-printed car in production\\%S19
\midrule
2023& The first implantable mobile phone available commercially\\%S01
& The first government to replace its census with big-data sources\\%S11
& \SI{10}{\percent} of reading glasses connected to the internet\\%S03
& \SI{80}{\percent} of people with a digital presence on the internet\\%S02
& Tax collected for the first time by a government via a blockchain\\%S18
& \SI{90}{\percent} of the population using smartphones\\%S06
\midrule
\rowcolor{cellHighlightColor}2024& \SI{90}{\percent} of the population with regular access to the internet\\%S05
\rowcolor{cellHighlightColor}& The first transplant of a 3D-printed liver\\%S20
\rowcolor{cellHighlightColor}& Over \SI{50}{\percent} of internet traffic to homes for appliances and devices\\%S09
\midrule
2025& \SI{5}{\percent} of consumer products printed in 3D\\%S21
& \SI{30}{\percent} of corporate audits performed by AI\\%S14
& Globally more trips/journeys via car sharing than in private cars\\%S17
\midrule
\rowcolor{cellHighlightColor}2026& Driverless cars equalling \SI{10}{\percent} of all cars on US roads\\%S12
\rowcolor{cellHighlightColor}& The first AI machine on a corporate board of directors\\%S13
\rowcolor{cellHighlightColor}& The first city with more than 50,000 people and no traffic lights\\%S10
\midrule
2027& \SI{10}{\percent} of global gross domestic product stored on blockchain technology\\%S16
\bottomrule
\end{tabular}
\end{small}
\end{table}
\end{document}
更新示例:修改了 MWE,可能修复了规则上方和下方缺失的颜色。仍在寻找缩进颜色问题的解决方案!
\documentclass[graybox,envcountchap,vecarrow,twoside]{svmono}
\usepackage[paperheight=240mm,paperwidth=170mm,top=2.5cm,inner=2.5cm]{geometry}
\usepackage{newtxtext}
\usepackage{newtxmath}
% Units
\usepackage[detect-weight=true,detect-family=true,per-mode=symbol,detect-all=true]{siunitx}
% Tables
\usepackage{booktabs}
\usepackage{multirow}
\usepackage{multicol}
\usepackage{makecell}
\usepackage{xcolor,colortbl}
\definecolor{cellHighlightColor}{rgb}{0.933333333333333 0.956862745098039 0.984313725490196}
\renewcommand{\arraystretch}{1.2}
\newcommand{\midlineColoredAbove}{%
\arrayrulecolor{cellHighlightColor}\specialrule{\aboverulesep}{0pt}{0pt}%
\arrayrulecolor{black}\specialrule{\lightrulewidth}{0pt}{0pt}%
\arrayrulecolor{white}\specialrule{\belowrulesep}{0pt}{0pt}%
\arrayrulecolor{black}%
}
\newcommand{\midlineColoredBelow}{%
\arrayrulecolor{black}%
\arrayrulecolor{white}\specialrule{\belowrulesep}{0pt}{0pt}%
\arrayrulecolor{black}\specialrule{\lightrulewidth}{0pt}{0pt}%
\arrayrulecolor{cellHighlightColor}\specialrule{\aboverulesep}{0pt}{0pt}%
}
\begin{document}
\begin{table}[!ht]
\centering
\caption{Predicted occurrence of technological ``tipping points''}
\begin{small}
\begin{tabular}{@{\hspace{6pt}}p{1.25cm}p{9cm}}
\toprule
Year& \multicolumn{1}{c}{Technological tipping points}\\
%\midrule
\midlineColoredBelow
\rowcolor{cellHighlightColor}2022& 1 trillion sensors connected to the internet\\%S08
\rowcolor{cellHighlightColor}& \SI{10}{\percent} of people wearing clothes connected to the internet\\%S04
\rowcolor{cellHighlightColor}& The first 3D-printed car in production\\%S19
%\midrule
\midlineColoredAbove
2023& The first implantable mobile phone available commercially\\%S01
& The first government to replace its census with big-data sources\\%S11
& \SI{10}{\percent} of reading glasses connected to the internet\\%S03
& \SI{80}{\percent} of people with a digital presence on the internet\\%S02
& Tax collected for the first time by a government via a blockchain\\%S18
& \SI{90}{\percent} of the population using smartphones\\%S06
%\midrule
\midlineColoredBelow
\rowcolor{cellHighlightColor}2024& \SI{90}{\percent} of the population with regular access to the internet\\%S05
\rowcolor{cellHighlightColor}& The first transplant of a 3D-printed liver\\%S20
\rowcolor{cellHighlightColor}& Over \SI{50}{\percent} of internet traffic to homes for appliances and devices\\%S09
%\midrule
\midlineColoredAbove
2025& \SI{5}{\percent} of consumer products printed in 3D\\%S21
& \SI{30}{\percent} of corporate audits performed by AI\\%S14
& Globally more trips/journeys via car sharing than in private cars\\%S17
%\midrule
\midlineColoredBelow
\rowcolor{cellHighlightColor}2026& Driverless cars equalling \SI{10}{\percent} of all cars on US roads\\%S12
\rowcolor{cellHighlightColor}& The first AI machine on a corporate board of directors\\%S13
\rowcolor{cellHighlightColor}& The first city with more than 50,000 people and no traffic lights\\%S10
%\midrule
\midlineColoredAbove
2027& \SI{10}{\percent} of global gross domestic product stored on blockchain technology\\%S16
\bottomrule
\end{tabular}
\end{small}
\end{table}
\end{document}
UPDATED 示例的输出:
答案1
该类svmono
将设置\tabcolsep
为1.5pt
。如果将其设置为,6pt
缩进将正确着色。
正如 Zarko 指出的那样,代码还存在一些其他问题(下面已修复):
\small
不是一个环境,而是一个开关(独立的,发布者可能不喜欢改变表格的字体大小;这是不好的做法)。- 您不应该加载
xcolor
,而colortbl
应该xcolor
使用[table]
选项加载。
\documentclass[graybox,envcountchap,vecarrow,twoside]{svmono}
\usepackage[paperheight=240mm,paperwidth=170mm,top=2.5cm,inner=2.5cm]{geometry}
\usepackage{newtxtext}
\usepackage{newtxmath}
% Units
\usepackage[detect-weight=true,detect-family=true,per-mode=symbol,detect-all=true]{siunitx}
% Tables
\usepackage{booktabs}
\usepackage{multirow}
\usepackage{multicol}
\usepackage{makecell}
\usepackage[table]{xcolor} % changed here
\definecolor{cellHighlightColor}{rgb}{0.933333333333333 0.956862745098039 0.984313725490196}
\renewcommand{\arraystretch}{1.2}
\newcommand{\midlineColoredAbove}{%
\arrayrulecolor{cellHighlightColor}\specialrule{\aboverulesep}{0pt}{0pt}%
\arrayrulecolor{black}\specialrule{\lightrulewidth}{0pt}{0pt}%
\arrayrulecolor{white}\specialrule{\belowrulesep}{0pt}{0pt}%
\arrayrulecolor{black}%
}
\newcommand{\midlineColoredBelow}{%
\arrayrulecolor{black}%
\arrayrulecolor{white}\specialrule{\belowrulesep}{0pt}{0pt}%
\arrayrulecolor{black}\specialrule{\lightrulewidth}{0pt}{0pt}%
\arrayrulecolor{cellHighlightColor}\specialrule{\aboverulesep}{0pt}{0pt}%
}
\begin{document}
\begin{table}[!ht]
\setlength{\tabcolsep}{6pt}
\centering
\caption{Predicted occurrence of technological ``tipping points''}
\small
\begin{tabular}{@{\hspace{6pt}}p{1.25cm}p{9cm}}
\toprule
Year& \multicolumn{1}{c}{Technological tipping points}\\
%\midrule
\midlineColoredBelow
\rowcolor{cellHighlightColor}2022& 1 trillion sensors connected to the internet\\%S08
\rowcolor{cellHighlightColor}& \SI{10}{\percent} of people wearing clothes connected to the internet\\%S04
\rowcolor{cellHighlightColor}& The first 3D-printed car in production\\%S19
%\midrule
\midlineColoredAbove
2023& The first implantable mobile phone available commercially\\%S01
& The first government to replace its census with big-data sources\\%S11
& \SI{10}{\percent} of reading glasses connected to the internet\\%S03
& \SI{80}{\percent} of people with a digital presence on the internet\\%S02
& Tax collected for the first time by a government via a blockchain\\%S18
& \SI{90}{\percent} of the population using smartphones\\%S06
%\midrule
\midlineColoredBelow
\rowcolor{cellHighlightColor}2024& \SI{90}{\percent} of the population with regular access to the internet\\%S05
\rowcolor{cellHighlightColor}& The first transplant of a 3D-printed liver\\%S20
\rowcolor{cellHighlightColor}& Over \SI{50}{\percent} of internet traffic to homes for appliances and devices\\%S09
%\midrule
\midlineColoredAbove
2025& \SI{5}{\percent} of consumer products printed in 3D\\%S21
& \SI{30}{\percent} of corporate audits performed by AI\\%S14
& Globally more trips/journeys via car sharing than in private cars\\%S17
%\midrule
\midlineColoredBelow
\rowcolor{cellHighlightColor}2026& Driverless cars equalling \SI{10}{\percent} of all cars on US roads\\%S12
\rowcolor{cellHighlightColor}& The first AI machine on a corporate board of directors\\%S13
\rowcolor{cellHighlightColor}& The first city with more than 50,000 people and no traffic lights\\%S10
%\midrule
\midlineColoredAbove
2027& \SI{10}{\percent} of global gross domestic product stored on blockchain technology\\%S16
\bottomrule
\end{tabular}
\end{table}
\end{document}
答案2
我建议使用更简单的代码,使用可选参数 解决颜色缩进问题\rowcolor
,这些参数设置左侧和右侧的颜色悬垂。此外,由于我们有p
类型列,我建议为每年制作一行。最后,我不再在彩色单元格的顶部和底部添加白色条纹,将规则填充设置为booktabs
0pt,并将其替换为我们可以使用包 定义的最小顶部和底部填充cellspace
,用于带有以字母为前缀的说明符的列中的单元格S
(或者C
如果加载siunitx
)。
无关:你确定需要 15 位十进制数字来定义一种颜色吗?;-)
\documentclass[graybox,envcountchap,vecarrow,twoside]{svmono}
\usepackage[paperheight=240mm,paperwidth=170mm,top=2.5cm,inner=2.5cm]{geometry}
\usepackage{newtxtext}
\usepackage{newtxmath}
% Units
\usepackage[detect-weight=true,detect-family=true,per-mode=symbol,detect-all=true]{siunitx}
% Tables
\usepackage{booktabs}
\usepackage{multirow}
\usepackage{multicol}
\usepackage{makecell, cellspace}
\usepackage[table]{xcolor}
\definecolor{cellHighlightColor}{rgb}{0.933333333333333 0.956862745098039 0.984313725490196}
\renewcommand{\arraystretch}{1.2}
\newcommand*\nl{\newline}
\begin{document}
\begin{table}[!ht]
\centering
\setlength{\aboverulesep}{0pt}
\setlength{\belowrulesep}{0pt}
\setlength{\cellspacetoplimit}{3pt}
\setlength{\cellspacebottomlimit}{3pt}
\caption{Predicted occurrence of technological ``tipping points''}
\small
\begin{tabular}{@{\hspace{6pt}}p{1.25cm}C{p{9cm}}}
\toprule
Year& \multicolumn{1}{c}{Technological tipping points}\\
\midrule
\rowcolor{cellHighlightColor}[6pt][1.5pt]2022 & 1 trillion sensors connected to the internet\nl%S08
\SI{10}{\percent} of people wearing clothes connected to the internet\nl%S04
The first 3D-printed car in production\\%S19
\midrule
2023 & The first implantable mobile phone available commercially\nl%S01
The first government to replace its census with big-data sources\nl%S11
\SI{10}{\percent} of reading glasses connected to the internet\nl%S03
\SI{80}{\percent} of people with a digital presence on the internet\nl%S02
Tax collected for the first time by a government via a blockchain\nl%S18
\SI{90}{\percent} of the population using smartphones\\%S06
\midrule
\rowcolor{cellHighlightColor}[6pt][1.5pt] 2024 & \SI{90}{\percent} of the population with regular access to the internet\nl%S05
The first transplant of a 3D-printed liver\nl%S20
Over \SI{50}{\percent} of internet traffic to homes for appliances and devices\\%S09
\midrule
2025& \SI{5}{\percent} of consumer products printed in 3D\nl%S21
\SI{30}{\percent} of corporate audits performed by AI\nl%S14
Globally more trips/journeys via car sharing than in private cars\\%S17
\midrule
\rowcolor{cellHighlightColor}[6pt][1.5pt] 2026 & Driverless cars equalling \SI{10}{\percent} of all cars on US roads\nl%S12
The first AI machine on a corporate board of directors\nl%S13
The first city with more than 50,000 people and no traffic lights\\%S10
\midrule
2027& \SI{10}{\percent} of global gross domestic product stored on blockchain technology\\%S16
\bottomrule
\end{tabular}
\end{table}
\end{document}