我怎样才能把线条覆盖所有的表格

我怎样才能把线条覆盖所有的表格

我有下表

\documentclass[a4paper]{article}
\usepackage[
top=2.5cm,
left=2.5cm,
bottom=2.5cm,
right=2.5cm
]{geometry}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[none]{hyphenat}
\usepackage{pdflscape}
\usepackage{longtable}
\usepackage{booktabs}
\usepackage{multirow}
\usepackage{multicol}
\usepackage{ltablex}
\sloppy
\begin{document}
\begin{landscape}
{\footnotesize%
\begin{tabularx}{\textheight}{llp{3cm}ccccX}
\toprule
\multicolumn{1}{l}{\multirow{2}[4]{*}{\textbf{Head 1}}} &
\multirow{2}[4]{*}{\textbf{Head 2}}                     &
\multirow{2}[4]{3cm}{\textbf{Head 3}}                   &
\multicolumn{4}{c}{\textbf{Head 4}}                     &
\multirow{2}[4]{*}{\textbf{Head 5}}                 \\
\cmidrule{4-7}                                  &   &   &
\textbf{Head 4.1} & \textbf{Head 4.2} & \textbf{Head 4.3} & \textbf{Head 4.4}&\\
\midrule
Column 1    &
Column 2 text   &
Column 3 has long texts &
Column 4 long cent texts    &
Column 5 long cent texts    &
Column 6 long cent texts    &
Column 7 long cent texts    &
Column 8 some text  \\
\end{tabularx}%
}
\end{landscape}
\end{document}

最后一列的表格线没有完全覆盖单元格。我该如何修复?

在此处输入图片描述

答案1

您的表格太宽,无法放入可用空间。一种解决方法是将四c列更改为类型C,其中C定义为X类型的居中版本。

在此处输入图片描述

\documentclass[a4paper]{article}
\usepackage[margin=2.5cm]{geometry}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[none]{hyphenat}
\usepackage{pdflscape,booktabs,multirow,multicol,ltablex,ragged2e}
\newcolumntype{C}{>{\Centering}X}
\sloppy
\begin{document}
\begin{landscape}
\footnotesize
\begin{tabularx}{\textwidth}{@{}llp{3cm}CCCCX@{}}
\toprule
\multirow{2}{*}{\textbf{Head 1}} &
\multirow{2}{*}{\textbf{Head 2}} &
\multirow{2}{3cm}{\textbf{Head 3}} &
\multicolumn{4}{c}{\textbf{Head 4}} &
\multirow{2}{*}{\textbf{Head 5}} \\
\cmidrule(lr){4-7} 
\textbf{Head 4.1} & \textbf{Head 4.2} & 
\textbf{Head 4.3} & \textbf{Head 4.4} \\
\midrule
Column 1    &
Column 2 text   &
Column 3 has long texts &
Column 4 long cent texts    &
Column 5 long cent texts    &
Column 6 long cent texts    &
Column 7 long cent texts    &
Column 8 some text  \\
\end{tabularx}
\end{landscape}
\end{document}

答案2

我建议采用稍微不同的布局,以适应\small字体大小:

\documentclass[a4paper]{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[margin=2.5cm]{geometry}
\usepackage[none]{hyphenat}
\usepackage{ragged2e}
\usepackage{pdflscape}
\usepackage{booktabs}
\usepackage{multirow}
\usepackage{multicol}
\usepackage{ltablex}
\sloppy

\begin{document}

\begin{landscape}
\small\setlength\tabcolsep{4pt}%
\begin{tabularx}{\linewidth}{ll>{\RaggedRight\arraybackslash}X*{6}{>{\centering\arraybackslash}X}>{\RaggedRight\arraybackslash}X}
\toprule
& & & \multicolumn{4}{c}{\textbf{Head 4}} \\
\cmidrule{4-7}
 \textbf{Head 1} & \textbf{Head 2} & \textbf{Head 3} &
 \textbf{Head 4.1} & \textbf{Head 4.2} & \textbf{Head 4.3} & \textbf{Head 4.4}& \textbf{Head 5}\\
\midrule
Column 1 &
Column 2 text &
Column 3 has long texts &
Column 4 long centred texts &
Column 5 long centred texts &
Column 6 long centred texts &
Column 7 long centred texts &
Column 8 some text \\
\end{tabularx}%
\end{landscape}

\end{document} 

在此处输入图片描述

相关内容