你好,我想给单元格添加“SMI”颜色。
\documentclass[]{book}
\usepackage{tabularx} % LINE-A
\usepackage{booktabs}
\usepackage{colortbl}
\begin{document}
\begin{table}[h]
\begin{center}
\begin{tabular}{lrr}
\toprule
Name & \multicolumn{1}{l}{\textbf{1989}} & \multicolumn{1}{l}{\textbf{1990}} \\
\midrule
\cellcolor[gray]{0.8}{ABB Ltd } & \multicolumn{1}{l}{SMI} & \multicolumn{1}{l}{SMI} \\
Actelion & \multicolumn{1}{l}{SMI} & \\
\bottomrule
\end{tabular}
\end{center}
\end{table}
\end{document}
我现在已经为单元格“ABB Ltd”着色,但是我该如何为单元格“SMI”着色呢?
答案1
这里有两种解决方案。请注意,booktabs
彩色单元格的顶部和底部都有一条白色条纹。如果您不想要它,您可以将 booktabs 替换为boldline + cellspace
以实现类似的效果:
\documentclass[]{book}
\usepackage{tabularx} % LINE-A
\usepackage[table, x11names]{xcolor}
\usepackage{booktabs}
\usepackage{colortbl}
\usepackage{cellspace, boldline}
\setlength\cellspacetoplimit{5pt}
\setlength\cellspacebottomlimit{5pt}
\begin{document}
\begin{table}[h]
\centering
\begin{tabular}{lrr}
\toprule
Name & \multicolumn{1}{l}{\textbf{1989}} & \multicolumn{1}{l}{\textbf{1990}} \\
\midrule
\rowcolor[gray]{0.8}{ABB Ltd } & \multicolumn{1}{l}{SMI} & \multicolumn{1}{l}{SMI} \\
Actelion & \multicolumn{1}{l}{\cellcolor[gray]{0.8}SMI} & \\
\bottomrule
\end{tabular}
\end{table}
\begin{table}[h]
\centering
\begin{tabular}{Slrr}
\hlineB{2}
Name & \multicolumn{1}{l}{\textbf{1989}} & \multicolumn{1}{l}{\textbf{1990}} \\
\hlineB{1.5}
\rowcolor[gray]{0.8}{ABB Ltd } & \multicolumn{1}{l}{SMI} & \multicolumn{1}{l}{SMI} \\
Actelion & \multicolumn{1}{l}{\cellcolor[gray]{0.8}SMI} & \\
\hlineB{2}
\end{tabular}
\end{table}
\end{document}