tabularx 包中的额外水平线

tabularx 包中的额外水平线

当我使用 tabularx 包生成表时,发生了以下情况:

    \documentclass [12pt]{book}
\usepackage{tabularx} % for stretching tables to page width
\usepackage{multirow} % for multiple rows in tables
\newcolumntype{Y}{>{\centering\arraybackslash}X} % for centering tables in tabularx
\def\tabularxcolumn#1{m{#1}}

\begin{document}

\begin{table}[H]
\centering
\begin{tabularx}{\textwidth}{|X|>{\hsize=.7\hsize}Y|>{\hsize=.7\hsize}Y|>{\hsize=.7\hsize}Y|>{\hsize=.7\hsize}Y|}
\hline
\multirow{3}{*}{\textbf{Components}} & \multirow{3}{*}{\textbf{Number}} & \multirow{3}{*}{\textbf{Algebra}} & \multirow{2}{*}{\textbf{Space and}} & \textbf{Statistics}\\
& & & \multirow{2}{*}{\textbf{shape}} & \textbf{and}\\
& & & & \textbf{probability}\\\hline
Core (Papers 1 \& 3) & 30--35\% & 20--25\% & 30--35\% &10--15\%\\\hline
\end{tabularx}
\end{table}

\end{document}

额外的水平线

如何去除表格右侧多余的水平线?

答案1

不要调整X列的宽度。而是调整真正想要不同的列,让X列均匀分布以填充剩余部分:

在此处输入图片描述

\documentclass{article}
\usepackage{tabularx,array,booktabs}
\newcolumntype{Y}{>{\centering\arraybackslash}X} % for centering tables in tabularx
\def\tabularxcolumn#1{m{#1}}
\newcommand{\heading}[1]{\bfseries\begin{tabular}{@{}c@{}} #1 \end{tabular}}

\begin{document}

\noindent
\begin{tabularx}{\textwidth}{
    >{\centering}m{.185\linewidth} 
    *{4}{Y} }
  \toprule
  \heading{Components} & \heading{Number} & \heading{Algebra} & \heading{Space and \\shape} & \heading{Statistics \\ and \\ probability} \\
  \midrule
  Core (Papers 1 \& 3) & 30--35\% & 20--25\% & 30--35\% & 10--15\% \\
  \bottomrule
\end{tabularx}

\end{document}

相关内容