1

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

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

enter image description here

2

2 Answers 2

2

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.

enter image description here

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

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

enter image description here

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .