1

The borders of this table do not close completely when I use the \multicolumn command. Also in the last row between columns C & D, I have the same problem. I am sure there is a easy fix to this, but struggling to find how.

\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\renewcommand{\arraystretch}{1.2}
\usepackage{tabularx}
\newcolumntype{P}[1]{>{\centering\arraybackslash}m{#1}}   
 
\begin{table}[htbp!]
    \centering
    \renewcommand{\arraystretch}{1.5}
    \begin{tabularx}{\textwidth}{|P{1.5cm}|P{3cm}|P{2.65cm}|P{1cm}|P{1cm}|P{1cm}|P{1cm}|}
    \hline
    \multicolumn{3}{l}{} & \multicolumn{4}{c}{Total count} \\
    \hline
    CLC  & CLC Description  & Ecological Impact Rating & S1 & S2 & S3 & S4\\
    \hline
    222, 223 & Fruit plantations and groves & 0.6   & 11    & 9     & 7     & 5 \\
    211, 213, 221, 241, 243 & Agricultural land & 0.8   & 3178  & 2726  & 1446  & 2238 \\
    311, 312, 313 & Forests & 1.0     & 3953  & 3804  & 2082  & 674 \\
    \hline
    \multicolumn{3}{l}{Calculated aggregate} & 6502 & 5990 & 3243 & 2467\\
    \hline
    \end{tabularx}
   
\end{table}
3
  • Welcome to TeX.SE.
    – Mico
    Dec 2, 2020 at 17:29
  • 2
    \multicolumn{4}{c} should be \multicolumn{4}{c|} to put the line back, and similarly the other cases Dec 2, 2020 at 17:31
  • @DavidCarlisle Thank you. You are a lifesaver! Dec 2, 2020 at 17:33

1 Answer 1

1

The main issue with your tabularx environment is that it doesn't contain any X-type columns; hence, there's no guarantee that its width will equal \textwidth. I'd assign a centered version of the X column type to columns 2 and 3 and the S column type (provided by the siunitx package) to columns 4 thru 7.

enter image description here

\documentclass{article} % or some other suitable document class

\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\renewcommand{\arraystretch}{1.2}
\usepackage{tabularx}
\renewcommand\tabularxcolumn[1]{m{#1}} % vertical centering
\newcolumntype{P}[1]{>{\centering\arraybackslash}m{#1}}   
\newcolumntype{C}{>{\centering\arraybackslash}X} 
\usepackage{siunitx} % for 'S' col. type
 
\begin{document}
\begin{table}[htbp!]
    %%\centering % redundant
    \renewcommand{\arraystretch}{1.5}
    \begin{tabularx}{\textwidth}{| P{1.5cm} |C|C| *{4}{S[table-format=4.0]|} }
    \hline
    CLC  & CLC Description  & Ecological Impact Rating & \multicolumn{4}{c|}{Total count} \\
    \cline{4-7}
    & & & {S1} & {S2} & {S3} & {S4} \\
    \hline
    222, 223 & Fruit plantations and groves & 0.6 & 11 & 9 & 7 & 5 \\
    211, 213, 221, 241, 243 & Agricultural land & 0.8 & 3178 & 2726 & 1446 & 2238 \\
    311, 312, 313 & Forests & 1.0 & 3953 & 3804 & 2082 & 674 \\
    \hline
    \multicolumn{3}{|r|}{Calculated aggregate} & 6502 & 5990 & 3243 & 2467\\
    \hline
    \end{tabularx}
   
\end{table}
\end{document}

You must log in to answer this question.

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