[Tex/LaTex] Extra horizontal lines in tabularx package

tabularx

When I use the tabularx package to generate a table, this happens:

    \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}

extra horizontal lines

How do I get rid of the extra horizontal lines on the right hand side of the table?

Best Answer

Don't adjust the width of the X-columns. Rather adjust the column that really want to be different and let the X-columns spread out evenly to fill the remainder:

enter image description here

\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}
Related Question