有人能帮忙突出显示表格中的某个特定单元格吗?我试过了,但出现未定义序列的错误。提前谢谢
\documentclass[12pt,listof=totoc,bibliography=totoc,numbers=noenddot]{scrartcl}
\usepackage[table]{xcolor}
\begin{document}
\begin{table}[hbt]
\centering
\captionabove{Initial assumed values}
\begin{tabular}{|p{3.5cm}|p{0.5cm}|p{0.5cm}| p{0.5cm}|p{0.5cm}| p{0.5cm}| p{0.5cm}|p{0.5cm}| p{0.5cm}| p{0.5cm}| p{0.5cm}|p{0.5cm}| }\hline
Parameter & 80 & 84 & 88 & 92 & 93 & 96 & 100 & 104 & 108 & 112 & 116 \\\hline
Cellular bacteria(\%) & \cellcolor{blue!25}$86.5$ & $62.5$ & $56.3$ & $37.5$ & $50$ & $50$ & $37.5$ & \cellcolor{blue!25}$87.5$ & $37.5$ & \cellcolor{blue!25}$75 $ & $66.7$ \\\hline
\end{tabular}
\end{table}
\end{document}
答案1
由于我无法使用更新的示例代码重现任何“未定义的控制序列”错误消息,因此我专注于输出中的缺陷。因此,这里有 4 个不同的表格,使用不同的字体大小和对齐方式,同时保持表格的原始样式不变:
\documentclass[12pt,listof=totoc,bibliography=totoc,numbers=noenddot]{scrartcl}
\usepackage[table]{xcolor}
\usepackage{calc}
\usepackage{tabularx}
\renewcommand{\tabularxcolumn}[1]{m{#1}}
\usepackage{siunitx}
\begin{document}
\begin{table}[hbt]
\centering
\captionabove{Initial assumed values - smaller font size, tabularx, equal column widths}
\small \setlength{\tabcolsep}{5pt}
\begin{tabularx}{\textwidth}{|X|*{11}{>{\centering\arraybackslash}m{\widthof{99.9}}|}}\hline
Parameter & {80} & {84} & {88} & {92} & {93} & {96} & {100} & {104} & {108} & {112} & {116} \\ \hline\hline
Cellular bacteria(\%) & \cellcolor{blue!25}86.5 & 62.5 & 56.3 & 37.5 & 50 & 50 & 37.5 & \cellcolor{blue!25}87.5 & 37.5 & \cellcolor{blue!25}75 & 66.7 \\\hline
\end{tabularx}
\end{table}
\begin{table}[hbt]
\centering
\captionabove{Initial assumed values - normal font size, tabularx, equal column width, vertically centered numbers}
\begin{tabularx}{\textwidth}{|>{\raggedright\arraybackslash}X|*{11}{>{\centering\arraybackslash}m{\widthof{99.9}}|}}\hline
Parameter & {80} & {84} & {88} & {92} & {93} & {96} & {100} & {104} & {108} & {112} & {116} \\ \hline\hline
Cellular bacteria(\%) & \cellcolor{blue!25}86.5 & 62.5 & 56.3 & 37.5 & 50 & 50 & 37.5 & \cellcolor{blue!25}87.5 & 37.5 & \cellcolor{blue!25}75 & 66.7 \\\hline
\end{tabularx}
\end{table}
\begin{table}[hbt]
\centering
\captionabove{Initial assumed values - normal font size, unequal column widths, tabularx}
\begin{tabularx}{\textwidth}{|>{\raggedright\arraybackslash}X|*{11}{c|}}\hline
Parameter & {80} & {84} & {88} & {92} & {93} & {96} & {100} & {104} & {108} & {112} & {116} \\ \hline\hline
Cellular bacteria(\%) & \cellcolor{blue!25}86.5 & 62.5 & 56.3 & 37.5 & 50 & 50 & 37.5 & \cellcolor{blue!25}87.5 & 37.5 & \cellcolor{blue!25}75 & 66.7 \\\hline
\end{tabularx}
\end{table}
\begin{table}[hbt]
\centering
\captionabove{Initial assumed values - normal font size, tabularx, equal column widths, alignment of numbers with siunitx}
\begin{tabularx}{\textwidth}{|>{\raggedright\arraybackslash}X|*{11}{S[table-format=2.1]|}}\hline
Parameter & {80} & {84} & {88} & {92} & {93} & {96} & {100} & {104} & {108} & {112} & {116} \\ \hline\hline
Cellular bacteria(\%) & \cellcolor{blue!25}86.5 & 62.5 & 56.3 & 37.5 & 50 & 50 & 37.5 & \cellcolor{blue!25}87.5 & 37.5 & \cellcolor{blue!25}75 & 66.7 \\\hline
\end{tabularx}
\end{table}
\end{document}
这里还有另一个关于如何基于booktabs
颜色而不是使用颜色来设计表格的建议:
\documentclass[12pt,listof=totoc,bibliography=totoc,numbers=noenddot]{scrartcl}
\usepackage{tabularx}
\usepackage{siunitx}
\usepackage{etoolbox}
\robustify\bfseries
\usepackage{booktabs}
\begin{document}
\begin{table}[hbt]
\centering
\captionabove{Initial assumed values - normal font size, tabularx, equal column widths, alignment of numbers with siunitx, no vertical lines, horizontal lines from booktabs, no color but bold instead to highlight numbers}
\begin{tabularx}{\textwidth}{>{\raggedright\arraybackslash}X*{11}{S[table-format=2.1,detect-weight]}}
\toprule
Parameter & {80} & {84} & {88} & {92} & {93} & {96} & {100} & {104} & {108} & {112} & {116} \\
\midrule
Cellular bacteria(\%) & \bfseries 86.5 & 62.5 & 56.3 & 37.5 & 50 & 50 & 37.5 & \bfseries 87.5 & 37.5 & \bfseries 75 & 66.7 \\
Cellular bacteria(\%) & 86 & 62.5 & 56.3 & 37.5 & 50.5 & 50.2 & 37.5 & 87.5 & 37.5 & 75 & 66.7 \\
\bottomrule
\end{tabularx}
\end{table}
\end{document}