0

I have this table that has around 10 columns and got columns headers intersect

how can I separate columns without changing the table design ( it is required to be in this design)

here is the script

\documentclass[computers,article,submit,moreauthors,pdftex]{Definitions/mdpi}

% MDPI internal commands - do not modify \firstpage{1} \makeatletter \setcounter{page}{@firstpage} \makeatother \pubvolume{1} \issuenum{1} \articlenumber{0} \pubyear{2023} \copyrightyear{2023} \datereceived{ } \daterevised{ } % Comment out if no revised date \dateaccepted{ } \datepublished{ } \hreflink{https://doi.org/} % If needed use \linebreak

\Title{Test}

\begin{document} \section{Background} This the table \ref{table_FinalDataset}

\begin{table}[H] \caption{xxxxxxxxxxxxxxxxxxxxx.} \label{table_FinalDataset} \newcolumntype{C}{>{\centering\arraybackslash}X} \begin{tabularx}{\textwidth}{CCCCCCCCCCC} \toprule \multirow{2}{*}{\textbf{Report ID}} & \multicolumn{5}{c}{\textbf{Features}} & \multicolumn{5}{c}{\textbf{Labels}} \ \cline{2-11} & \textbf{C0004482} & \textbf{C0224473} & \textbf{C0719349} & \textbf{C0230431} & \textbf{C0420607} & \textbf{295} & \textbf{300} & \textbf{303} & \textbf{540} & \textbf{560}\ \midrule 1012 &6 &0 &0 &4 &2 &0 &1 &1 &0 &0\
1013 &0 &2 &2 &8 &0 &1 &1 &0 &0 &1 \
1014 &0 &0 &4 &4 &9 &1 &0 &1 &0 &0 \

\bottomrule \end{tabularx} \end{table} \end{document}

JamesT
  • 3,169
asmgx
  • 437
  • 1
    You're asking for 10 equal width columns that take up the entire width of the page, but you're not wanting to change the table design. But you have wide column headers. How would you make things fit? (And please make your code self contained. We don't have mdpi.) – Teepeemm Mar 13 '23 at 04:14
  • 1
    What you're trying to achieve is similar to shrinking down 2kg of stuff into a 1kg container. Something has to give: The margins or possibly the font size. Perhaps this will help: My table doesn't fit; what are my options? – Werner Mar 13 '23 at 04:14
  • @Teepeemm The code (I expect) is self contained, I ran it on Overleaf as is and worked fine, anyway, the columns should not be equal, some columns may larger than others and font size can change too – asmgx Mar 13 '23 at 15:19
  • It works on Overleaf because you have Definitions/mdpi.cls. If you don't need the columns equal, then why are you making them all type C instead of type c? – Teepeemm Mar 13 '23 at 15:21
  • @Teepeemm because I do not know the difference between C and c. Thanks for the info' – asmgx Mar 13 '23 at 15:23

1 Answers1

2

Your problem is that the "Features" are long column entries, and the X column type (which is what you're defining C to be) makes all of the columns the same width. If you switch to c columns, then they'll be wide enough for their contents, but the table will (most likely) be too wide for the text area. "How should you fit the text?" is a question that you need to answer before turning to TeX to implement that "how".

One option is to rotate the Feature column labels. That's not usually viewed favorably, so I'll make you look that up if you want it. A second option would be to stagger the feature column labels in alternate rows. A third option (my preference) would be to separate the "Features" and "Labels" portion into separate tables.

Option 2:
option 2 output

Option 3:
option 3 output

\documentclass{article}

\usepackage{tabularx} \usepackage{booktabs}

\begin{document} \section{Background} This the table \ref{table_FinalDataset}

% option 2 \begin{table} \caption{xxxxxxxxxxxxxxxxxxxxx.} \label{table_FinalDataset} \newcolumntype{C}{>{\centering\arraybackslash}X} \begin{tabularx}{\textwidth}{cCCCCCccccc} \toprule \textbf{Report} & \multicolumn{5}{c}{\textbf{Features}} & \multicolumn{5}{c}{\textbf{Labels}} \ \cmidrule(lr){2-6}\cmidrule(l){7-11} \textbf{ID} & & \makebox[0pt]{\textbf{C0224473}} & & \makebox[0pt]{\textbf{C0230431}} & & \textbf{295} & \textbf{300} & \textbf{303} & \textbf{540} & \textbf{560}\ & \makebox[0pt]{\textbf{C0004482}} & & \makebox[0pt]{\textbf{C0719349}} && \makebox[0pt]{\textbf{C0420607}} \ \midrule 1012 &6 &0 &0 &4 &2 &0 &1 &1 &0 &0\
1013 &0 &2 &2 &8 &0 &1 &1 &0 &0 &1 \
1014 &0 &0 &4 &4 &9 &1 &0 &1 &0 &0 \

\bottomrule \end{tabularx} \end{table}

\clearpage

% option 3a \begin{table}[h]\small \caption{Features by Report ID.} \label{table_FinalDataset_features} \begin{tabular}{\textwidth}{cccccc} \toprule \textbf{Report ID} & \textbf{C0004482} & \textbf{C0224473} & \textbf{C0719349} & \textbf{C0230431} & \textbf{C0420607} \ \midrule 1012 &6 &0 &0 &4 &2\
1013 &0 &2 &2 &8 &0\
1014 &0 &0 &4 &4 &9\ \bottomrule \end{tabular
} \end{table}

% option 3b \begin{table}[h]\centering \caption{Labels by Report ID.} \label{table_FinalDataset_labels} \begin{tabular}{cccccc} \toprule \textbf{Report ID} & \textbf{295} & \textbf{300} & \textbf{303} & \textbf{540} & \textbf{560}\ \midrule 1012 &0 &1 &1 &0 &0\
1013 &1 &1 &0 &0 &1 \
1014 &1 &0 &1 &0 &0 \ \bottomrule \end{tabular} \end{table} \end{document}

Teepeemm
  • 6,708