2

I'm trying to create the below table by using the below packages, but the format of it is not well organised especially the numbers as they need to be in the centre and the tabs. can someone please help to make the table more adjustable and look professional?

\documentclass[conference]{IEEEtran}
\IEEEoverridecommandlockouts

\usepackage{booktabs,tabulary,lipsum}
\usepackage{dcolumn,tipa}
\newcolumntype{d}{D{.}{.}{6.5}}
\usepackage{siunitx}
\usepackage[usestackEOL]{stackengine}
\usepackage{multirow}


\begin{document}

\begin{table*}[ht]
\caption{Table ex.}
\label{tab1}
\centering
\renewcommand\footnoterule{\kern -1ex}
\renewcommand{\arraystretch}{1.3}
\begin{tabular*}{\linewidth}{l*{9}{d}}
\toprule \multirow{3}{*}{Subjects}   & 

\multicolumn{4}{c}{Numbers} & 
\multicolumn{4}{c}{Numbers}\\
\cmidrule(r){2-5}\cmidrule(l){6-9}  &
\multicolumn{1}{c}{XYZ} & 
\multicolumn{1}{c}\addstackgap{\stackanchor{XYZ}{(Numbers)}} & 
\multicolumn{1}{c}{Numbers Tree} & 
\multicolumn{1}{c}{Numbers Tree} & 
\multicolumn{1}{c}{XYZ} & 
\multicolumn{1}{c}\addstackgap{\stackanchor{XYZ}{(Numbers)}} & 
\multicolumn{1}{c}{Numbers Tree} & 
\multicolumn{1}{c}{Numbers Tree} \\\midrule 
 
X1 & 0.5000 & 0.4888 & 0.0112 & 0.0001 & 0.8500 & 0.3540 & 0.2332 & 0.2367 \\

X2 & 0.5000 & 0.4888 & 0.0112 & 0.0001 & 0.8500 & 0.3540 & 0.2332 & 0.2367 \\ 

X3 & 0.5000 & 0.4888 & 0.0112 & 0.0001 & 0.8500 & 0.3540 & 0.2332 & 0.2367 \\ 

X4 & 0.5000 & 0.4888 & 0.0112 & 0.0001 & 0.8500 & 0.3540 & 0.2332 & 0.2367 \\ 

X5 & 0.5000 & 0.4888 & 0.0112 & 0.0001 & 0.8500 & 0.3540 & 0.2332 & 0.2367 \\\bottomrule
\end{tabular*}

\end{table*}

\end{document}

And the result is this:

enter image description here

1
  • Welcome to TeX.SE.
    – Mico
    Feb 16, 2021 at 13:32

2 Answers 2

1

You should use the S columns of siunitx.

 \documentclass[conference]{IEEEtran}
 \IEEEoverridecommandlockouts

 \usepackage{booktabs,tabulary,lipsum}
 \usepackage{dcolumn,tipa}
 \newcolumntype{d}{D{.}{.}{6.5}}
 \usepackage{siunitx}
 \usepackage[usestackEOL]{stackengine}
 \usepackage{multirow}


 \begin{document}

 \begin{table*}[ht]
 \sisetup{
 table-number-alignment = center,
 table-figures-integer = 1,
 table-figures-decimal = 4
 }
 \caption{Table ex.}
 \label{tab1}
 \centering
 \renewcommand\footnoterule{\kern -1ex}
 \renewcommand{\arraystretch}{1.3}
 \begin{tabular}{l*{8}{S}}
 \toprule \multirow{3}{*}{Subjects}   & 
 \multicolumn{4}{c}{Numbers} & 
 \multicolumn{4}{c}{Numbers}\\
 \cmidrule(r){2-5}\cmidrule(l){6-9}  &
 \multicolumn{1}{c}{XYZ} & 
 \multicolumn{1}{c}\addstackgap{\stackanchor{XYZ}{(Numbers)}} & 
 \multicolumn{1}{c}{Numbers Tree} & 
 \multicolumn{1}{c}{Numbers Tree} & 
 \multicolumn{1}{c}{XYZ} & 
 \multicolumn{1}{c}\addstackgap{\stackanchor{XYZ}{(Numbers)}} & 
 \multicolumn{1}{c}{Numbers Tree} & 
 \multicolumn{1}{c}{Numbers Tree} \\\midrule 
 X1 & 0.5000 & 0.4888 & 0.0112 & 0.0001 & 0.8500 & 0.3540 & 0.2332 & 0.2367 \\
 X2 & 0.5000 & 0.4888 & 0.0112 & 0.0001 & 0.8500 & 0.3540 & 0.2332 & 0.2367 \\ 
 X3 & 0.5000 & 0.4888 & 0.0112 & 0.0001 & 0.8500 & 0.3540 & 0.2332 & 0.2367 \\ 
 X4 & 0.5000 & 0.4888 & 0.0112 & 0.0001 & 0.8500 & 0.3540 & 0.2332 & 0.2367 \\ 
 X5 & 0.5000 & 0.4888 & 0.0112 & 0.0001 & 0.8500 & 0.3540 & 0.2332 & 0.2367 \\\bottomrule
 \end{tabular}

 \end{table*}

 \end{document}

Output of the above code

1
  • You may also want to point out explicitly that you switched from a tabular* to a tabular environment.
    – Mico
    Feb 16, 2021 at 13:33
0

The main problem with your table is the unfortunate choice of 6.5 to format the 8 numerical columns; it should be 1.4 throughout. A second issue is that you employ a tabular* environment but give LaTeX no chance to achieve the desired overall width (here: \linewidth). Finally, there are only 8, not 9, columns of type d.

enter image description here

\documentclass[conference]{IEEEtran}
\IEEEoverridecommandlockouts

\usepackage{booktabs}
\usepackage{dcolumn,tipa}
\newcolumntype{d}[1]{D{.}{.}{#1}} % let the 'd' column type take an argument
%\usepackage{siunitx}             % not needed for this example
\usepackage[usestackEOL]{stackengine}
\usepackage{multirow}
\newcommand\mcc[1]{\multicolumn{1}{c}{#1}} % handy shortcut macro

\begin{document}

\begin{table*}[ht]
\caption{Table example}
\label{tab1}
%%\centering % redundant
%%\renewcommand\footnoterule{\kern -1ex} % What is this instruction doing here??
\renewcommand{\arraystretch}{1.3}
\setlength\tabcolsep{0pt} % make LaTeX figure out the intercolumn separation
\begin{tabular*}{\linewidth}{@{\extracolsep{\fill}} l *{8}{d{1.4}} } % '1.4', not '6.5'
\toprule 
\multirow{3}{*}{Subjects} & \multicolumn{4}{c}{Numbers} & \multicolumn{4}{c}{Numbers}\\
\cmidrule{2-5} \cmidrule{6-9} &
\mcc{XYZ} & \mcc{\addstackgap{\stackanchor{XYZ}{(Numbers)}}} & 
\mcc{Numbers Tree} & \mcc{Numbers Tree} & 
\mcc{XYZ} & \mcc{\addstackgap{\stackanchor{XYZ}{(Numbers)}}} & 
\mcc{Numbers Tree} & \mcc{Numbers Tree} \\
\midrule 
X1 & 0.5000 & 0.4888 & 0.0112 & 0.0001 & 0.8500 & 0.3540 & 0.2332 & 0.2367 \\ 
X2 & 0.5000 & 0.4888 & 0.0112 & 0.0001 & 0.8500 & 0.3540 & 0.2332 & 0.2367 \\ 
X3 & 0.5000 & 0.4888 & 0.0112 & 0.0001 & 0.8500 & 0.3540 & 0.2332 & 0.2367 \\ 
X4 & 0.5000 & 0.4888 & 0.0112 & 0.0001 & 0.8500 & 0.3540 & 0.2332 & 0.2367 \\ 
X5 & 0.5000 & 0.4888 & 0.0112 & 0.0001 & 0.8500 & 0.3540 & 0.2332 & 0.2367 \\
\bottomrule
\end{tabular*}
\end{table*}
\end{document}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.