I want to create a table in this format, but I haven't managed to get it to work. I dont need to have any colour, i would just like to have it shown as a plain table.
3 Answers
You're right about not wanting colors; however, you don't want vertical rules either. Nor it's necessary that “Data set” is lowered: the first row has the column headers, some of which have subheaders in the second row, with a horizontal rule to show the groups.
With siunitx
and its S
column you can get exact spacing between columns, alignment under the decimal point and automatic management of numbers (see in the eighth column).
The input is straightforward; only some care is needed for adjusting the column specifiers, which can be done when the data are in their final form.
A local setting of \tabcolsep
is necessary, at least for the standard text width; if you have a different text width you may be able to omit the setting or you may need to change the size.
\documentclass[11pt]{article}
\usepackage{siunitx}
\usepackage{booktabs}
\begin{document}
\begin{tabular}{
l
*{6}{S[table-format=1.4]}
S[table-format=5]
S[table-format=3.2]
}
\toprule
\multicolumn{1}{c}{Data Set} &
\multicolumn{3}{c}{Balanced Error} &
\multicolumn{3}{c}{Area Under Curve} &
\multicolumn{2}{c}{Features} \\
\cmidrule(lr){2-4} \cmidrule(lr){5-7} \cmidrule(lr){8-9}
& {Train} & {Valid} & {Test} & {Train} & {Valid} & {Test} & {\#} & {\%} \\
\midrule
arcene & 0.5000 & 0.4886 & 0.5006 & 0.5000 & 0.5114 & 0.4994 & 10000 & 100.10 \\
gisette & 0.5000 & 0.4886 & 0.5006 & 0.5000 & 0.5114 & 0.4994 & 10000 & 100.10 \\
dexter & 0.5000 & 0.4886 & 0.5006 & 0.5000 & 0.5114 & 0.4994 & 10000 & 100.10 \\
madelon & 0.5000 & 0.4886 & 0.5006 & 0.5000 & 0.5114 & 0.4994 & 10000 & 100.10 \\
\bottomrule
\end{tabular}
\end{document}
-
Can
Data Set
label centered in between the top and lower lines? like @Jared Lo's answer– alperCommented Sep 26, 2022 at 16:19 -
1@alper Why would you? The header belongs in the same level as “Balanced Errors” and so on. You can use the same strategy as in the answer you're referring to, but I consider it bad style.– egregCommented Sep 26, 2022 at 16:25
-
-
for the
siunitx
format what should I do if I have a variables as following pattern50/60
; usingS[table-format=5]
for 5 characters did not help– alperCommented Sep 26, 2022 at 17:34 -
@alper
S
column type is for aligning decimal numbers at the decimal separator.– egregCommented Sep 26, 2022 at 17:40
Several good answers already exist. I'd like to suggest to use the booktabs
package as it creates tables that are effective and yet simple to create.
\documentclass[11pt]{article}
\usepackage{booktabs}
\let\mc\multicolumn
\begin{document}
\begin{tabular}{r rrr rrr rr}
\toprule
& \mc3c{Balanced Error}
& \mc3c{Area Under Curve}
& \mc2c{Features} \\
\cmidrule(r){2-4}
\cmidrule{5-7}
\cmidrule(l){8-9}
Data Set & Train &Valid &Test & Train &Valid & Test & \# & \% \\
\midrule
arcene&0.5000 &0.4886 &0.5006 & 0.5000 &0.5114 &0.4994 &10000 & 100.10\\
gisette&0.5000 &0.4886 &0.5006 & 0.5000 &0.5114 &0.4994 &10000 & 100.10\\
dexter&0.5000 &0.4886 &0.5006 & 0.5000 &0.5114 &0.4994 &10000 & 100.10\\
madelon&0.5000 &0.4886 &0.5006 & 0.5000 &0.5114 &0.4994 &10000 & 100.10\\
\bottomrule
\end{tabular}
\end{document}
you need to load packages multirow and multicol in the preamble and then :
\begin{table}[htdp]
\caption{default}
\begin{center}
\begin{tabular}{|c|c|c|c|c|c|c|c|c|}
\multirow{2}{*}{Data set}&\multicolumn{3}{c|}{Balanced Error}&\multicolumn{3}{c|}{Area under Curve}&\multicolumn{2}{c|}{Features}\\ \cline{2-9}
&Train&Valid&Tes&Train&Valid&Test&\#&\%\\ \hline
arcene&0.5000&0.5000&0.5000&0.5000&0.5000&0.5000&0.5000&0.5000\\
gisette&0.5000&0.5000&0.5000&0.5000&0.5000&0.5000&0.5000&0.5000\\
dexter&0.5000&0.5000&0.5000&0.5000&0.5000&0.5000&0.5000&0.5000\\
madelon&0.5000&0.5000&0.5000&0.5000&0.5000&0.5000&0.5000&0.5000
\end{tabular}
\end{center}
\label{default}
\end{table}