当我使用 \multicolumn 命令时,此表的边框无法完全关闭。在 C 列和 D 列之间的最后一行,我也遇到了同样的问题。我相信这个问题有一个简单的解决方法,但我不知道该如何解决。
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\renewcommand{\arraystretch}{1.2}
\usepackage{tabularx}
\newcolumntype{P}[1]{>{\centering\arraybackslash}m{#1}}
\begin{table}[htbp!]
\centering
\renewcommand{\arraystretch}{1.5}
\begin{tabularx}{\textwidth}{|P{1.5cm}|P{3cm}|P{2.65cm}|P{1cm}|P{1cm}|P{1cm}|P{1cm}|}
\hline
\multicolumn{3}{l}{} & \multicolumn{4}{c}{Total count} \\
\hline
CLC & CLC Description & Ecological Impact Rating & S1 & S2 & S3 & S4\\
\hline
222, 223 & Fruit plantations and groves & 0.6 & 11 & 9 & 7 & 5 \\
211, 213, 221, 241, 243 & Agricultural land & 0.8 & 3178 & 2726 & 1446 & 2238 \\
311, 312, 313 & Forests & 1.0 & 3953 & 3804 & 2082 & 674 \\
\hline
\multicolumn{3}{l}{Calculated aggregate} & 6502 & 5990 & 3243 & 2467\\
\hline
\end{tabularx}
\end{table}
答案1
您的环境的主要问题tabularx
是它不包含任何X
类型列;因此,不能保证其宽度等于\textwidth
。我会将列类型的居中版本分配X
给第 2 列和第 3 列,并将S
列类型(由包提供siunitx
)分配给第 4 列至第 7 列。
\documentclass{article} % or some other suitable document class
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\renewcommand{\arraystretch}{1.2}
\usepackage{tabularx}
\renewcommand\tabularxcolumn[1]{m{#1}} % vertical centering
\newcolumntype{P}[1]{>{\centering\arraybackslash}m{#1}}
\newcolumntype{C}{>{\centering\arraybackslash}X}
\usepackage{siunitx} % for 'S' col. type
\begin{document}
\begin{table}[htbp!]
%%\centering % redundant
\renewcommand{\arraystretch}{1.5}
\begin{tabularx}{\textwidth}{| P{1.5cm} |C|C| *{4}{S[table-format=4.0]|} }
\hline
CLC & CLC Description & Ecological Impact Rating & \multicolumn{4}{c|}{Total count} \\
\cline{4-7}
& & & {S1} & {S2} & {S3} & {S4} \\
\hline
222, 223 & Fruit plantations and groves & 0.6 & 11 & 9 & 7 & 5 \\
211, 213, 221, 241, 243 & Agricultural land & 0.8 & 3178 & 2726 & 1446 & 2238 \\
311, 312, 313 & Forests & 1.0 & 3953 & 3804 & 2082 & 674 \\
\hline
\multicolumn{3}{|r|}{Calculated aggregate} & 6502 & 5990 & 3243 & 2467\\
\hline
\end{tabularx}
\end{table}
\end{document}