# How can I put lines covering all table

I have the following table

\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
\cmidrule{4-7}                                  &   &   &
\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}


Te table lines in the last colum are not covering totally the cell. How can i fix it?

• I think it is better to use \linewidth instead of \textwidth as the width of your table especially when you are using landscape pages. This should also solve the problem you describe. – user3653085 Aug 25 '17 at 20:16
• Since you have some responses below that seem to answer your question, please consider marking one of them as ‘Accepted’ by clicking on the tickmark below their vote count (see How do you accept an answer?). This shows which answer helped you most, and it assigns reputation points to the author of the answer (and to you!). It's part of this site's idea to identify good questions and answers through upvotes and acceptance of answers. – user36296 Sep 26 '17 at 16:39

Your table is simply too wide to fit inside the available space. One way to fix things is to change the four c columns to type C, where C is defined as a centered version of the X type.

\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
\cmidrule(lr){4-7}
\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}


I propose a slightly different layout, allowing for \small font size:

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