如何为多行和多列表格添加颜色?

如何为多行和多列表格添加颜色?

我有这张表。我想将左列(带有单词 Template 的两个单元格)涂成蓝色。我还想将第一行、从 Lineal 到 Tesla 的所有单元格涂成灰色,如果可能的话,将数字 1、2、3、4、0.15... 的单元格涂成其他颜色。我该怎么做?我尝试使用 \colorcolumn,但它不起作用。

\documentclass{article}
\usepackage{multirow}
\usepackage[margin=25mm,showframe]{geometry}

\begin{document}
\begin{table}[h]
\centering
\small
\setlength\tabcolsep{3.6pt}
\begin{tabular}{ | l | *{16}{c |}}
\hline
\multirow{2}{14mm}{\textbf{Method\newline Function}} & \multirow{2}{*}{Lineal} & \multicolumn{4}{c|}{Pol, for grade} &     \multicolumn{5}{c|}{Gaussian, for deviation $\sigma$} & \multirow{2}{12mm}{\centering S\\ method} & \multirow{2}{*}{Line} & \multirow{2}{*}{Upload} & \multirow{2}{*}{Fourier} & \multirow{2}{*}{Marconi} & \multirow{2}{*}{Tesla} \\
\cline{3-11}
& & 1 & 2 & 3 & 4 & $0.15$ & $0.25$ & $0.5$ & $2$ & $3$ & & & & & &\\
\hline
Template & 57\% & 80\% & 92 & 89 & 89 & 94 & 97 & 97 & 94 & 92 & a & b & c & d & e & f \\
\hline
Template & 57\% & 80\% & 92 & 89 & 89 & 94 & 97 & 97 & 94 & 92 & a & b & c & d & e & f \\
\hline
\end{tabular}
\end{table}
\end{document}

答案1

借助colortbl多行命令并进行一些更改,您将获得类似以下内容的结果

\documentclass{article}
\usepackage{multirow}
\usepackage{xcolor}
\usepackage{colortbl}
\usepackage[margin=25mm,showframe]{geometry}

\begin{document}
\begin{table}[h]
\centering
\small
\setlength\tabcolsep{3.6pt}
\begin{tabular}{ | l | *{16}{c |}}
\hline
\rowcolor{gray} && \multicolumn{4}{c|}{Pol, for grade} & \multicolumn{5}{c|}{\cellcolor{gray}Gaussian, for deviation $\sigma$} &  &  &  &  &  &  \\
\cline{3-11}
\rowcolor{gray} \multirow{-2}{14mm}{\textbf{Method\newline Function}} & \multirow{-2}{*}{Lineal} & \cellcolor{gray!40} 1 & \cellcolor{gray!40} 2 &\cellcolor{gray!40} 3 &\cellcolor{gray!40} 4 &\cellcolor{gray!40} $0.15$ & \cellcolor{gray!40}$0.25$ &\cellcolor{gray!40} $0.5$ & \cellcolor{gray!40}$2$ &\cellcolor{gray!40} $3$ & \multirow{-2}{12mm}{\centering S\\ method} & \multirow{-2}{*}{Line} & \multirow{-2}{*}{Upload} & \multirow{-2}{*}{Fourier} & \multirow{-2}{*}{Marconi} & \multirow{-2}{*}{Tesla}\\
\hline
\cellcolor{blue}Template & 57\% & 80\% & 92 & 89 & 89 & 94 & 97 & 97 & 94 & 92 & a & b & c & d & e & f \\
\hline
\cellcolor{blue}Template & 57\% & 80\% & 92 & 89 & 89 & 94 & 97 & 97 & 94 & 92 & a & b & c & d & e & f \\
\hline
\end{tabular}
\end{table}
\end{document}

相关内容