我想给表格中的一行着色,但是出现了问题。我怎样才能给一行完全着色?(表格宽度应等于文本宽度。)
\documentclass{article}
\usepackage{xcolor,colortbl}
\newcommand{\mc}[2]{\multicolumn{#1}{c}{#2}}
\definecolor{Gray}{gray}{0.85}
\definecolor{LightCyan}{rgb}{0.88,1,1}
\newcolumntype{a}{>{\columncolor{Gray}}c}
\newcolumntype{b}{>{\columncolor{white}}c}
\begin{document}
\begin{table}
\begin{tabular}{cccccc}
\hline
\rowcolor{LightCyan}
$V_{CN}^{*}$ & ${{E}_{11}}\left( \text{GPa} \right)$ &${{\eta}_{1}}$ & ${{E}_{22}}\left( \text{GPa} \right)$ & ${{\eta}_{2}}$ & ${{\eta}_{3}}$ \\
\hline
0.11 & 94.4168 & 0.149 & 2.2037 & 0.934 & 0.934 \\
0.14 & 120.3846 & 0.15 & 2.2977 & 0.941 & 0.941 \\
0.17 & 144.7714 & 0.149 & 3.4939 & 1.381 & 1.381 \\
\end{tabular}
\end{table}
\begin{table}
\begin{tabular*}{\textwidth}{c @{\extracolsep{\fill}} cccccc}
\hline
\rowcolor{LightCyan}
$V_{CN}^{*}$ & ${{E}_{11}}\left( \text{GPa} \right)$ &${{\eta}_{1}}$ & ${{E}_{22}}\left( \text{GPa} \right)$ & ${{\eta}_{2}}$ & ${{\eta}_{3}}$ \\
\hline
0.11 & 94.4168 & 0.149 & 2.2037 & 0.934 & 0.934 \\
0.14 & 120.3846 & 0.15 & 2.2977 & 0.941 & 0.941 \\
0.17 & 144.7714 & 0.149 & 3.4939 & 1.381 & 1.381 \\
\end{tabular*}
\end{table}
\end{document}
但当它等于宽度时
答案1
确实,您所需要的只是:
\usepackage{tabularx}
\newcolumntype{C}{>{\centering\arraybackslash}X}
然后,而不是tabular*
使用:
\begin{tabularx}{\textwidth}{C CCC CCC}
...
\end{tabularx}
采用您的示例(稍作修改),然后进行以下更改:
\documentclass{article}
\usepackage{xcolor,colortbl, amsmath, tabularx}
\newcommand{\mc}[2]{\multicolumn{#1}{c}{#2}}
\definecolor{Gray}{gray}{0.85}
\definecolor{LightCyan}{rgb}{0.88,1,1}
\newcolumntype{a}{>{\columncolor{Gray}}c}
\newcolumntype{b}{>{\columncolor{white}}c}
\newcolumntype{C}{>{\centering\arraybackslash}X}
\begin{document}
\begin{table}
\begin{tabular}{cccccc}
\hline
\rowcolor{LightCyan}
$V_{CN}^{*}$ & ${{E}_{11}}\left( \text{GPa} \right)$ &${{\eta}_{1}}$ & ${{E}_{22}}\left( \text{GPa} \right)$ & ${{\eta}_{2}}$ & ${{\eta}_{3}}$ \\
\hline
0.11 & 94.4168 & 0.149 & 2.2037 & 0.934 & 0.934 \\
0.14 & 120.3846 & 0.15 & 2.2977 & 0.941 & 0.941 \\
0.17 & 144.7714 & 0.149 & 3.4939 & 1.381 & 1.381 \\
\end{tabular}
\end{table}
\begin{table}
%\begin{tabular*}{\textwidth}{c @{\extracolsep{\fill}} ccc ccc}
\begin{tabularx}{\textwidth}{C CCC CCC}
\hline
\rowcolor{LightCyan}
$V_{CN}^{*}$ & ${{E}_{11}}\left( \text{GPa} \right)$ &${{\eta}_{1}}$ & ${{E}_{22}}\left( \text{GPa} \right)$ & ${{\eta}_{2}}$ & ${{\eta}_{3}}$ \\
\hline
0.11 & 94.4168 & 0.149 & 2.2037 & 0.934 & 0.934 \\
0.14 & 120.3846 & 0.15 & 2.2977 & 0.941 & 0.941 \\
0.17 & 144.7714 & 0.149 & 3.4939 & 1.381 & 1.381 \\
%\end{tabular*}
\end{tabularx}
\end{table}
\end{document}