我正在使用IEEEtran
带有选项的类journal
。我想并排插入两个表格,每个表格都有各自的子标题。但是,当我使用该subcaption
包时,我得到了以下结果:
我的代码是:
\begin{table}[]
\centering
\begin{subtable}[c]{0.25\textwidth}
\centering
\begin{tabular}{lll}
& \textbf{Original} & \textbf{SMOTE-Tomek} \\ \hline
\textbf{class 0} & 11645 & 10444 \\ \hline
\textbf{class 1} & 618 & 10305 \\ \hline
\textbf{class 2} & 618 & 9976 \\ \hline
\textbf{class 3} & 682 & 11597 \\ \hline
\textbf{class 4} & 736 & 10190 \\ \hline
\textbf{class 5} & 829 & 10462 \\ \hline
\end{tabular}
\subcaption{Client 1 balance by SMOTE-Tomek}
\end{subtable}%
\begin{subtable}[c]{0.25\textwidth}
\centering
\begin{tabular}{lll}
& \textbf{Original} & \textbf{SMOTE-Tomek} \\ \hline
\textbf{class 0} & 11645 & 10444 \\ \hline
\textbf{class 1} & 618 & 10305 \\ \hline
\textbf{class 2} & 618 & 9976 \\ \hline
\textbf{class 3} & 682 & 11597 \\ \hline
\textbf{class 4} & 736 & 10190 \\ \hline
\textbf{class 5} & 829 & 10462 \\ \hline
\end{tabular}
\subcaption{Client 2 balance by SMOTE-Tomek}
\end{subtable}
\caption{principal}
\茶几}
答案1
看起来tabular
环境的宽度超出了0.25\textwidth
。首先,我会tabular
通过强制在标题单元格中换行来缩小环境的宽度SMOTE-Tomek
。
我还会尝试使用软件包的机制booktabs
(特别是用户宏\toprule
、\midrule
、\bottomrule
)让表格材料看起来更具吸引力,同时删除所有 实例\hline
。最后,我会将数字排列在它们的(隐式)小数点上,我不会使用大胆的在标题单元格中,因为根本就不需要。
\documentclass[journal]{IEEEtran}
\usepackage{subcaption,lipsum,booktabs}
\usepackage{siunitx} % for 'S' column type
\begin{document}
\begin{table}
\captionsetup[subtable]{justification=centering} % optional
\begin{subtable}{0.45\columnwidth}
\centering
\begin{tabular}{@{} l *{2}{S[table-format=5.0,group-four-digits=true]} @{}}
\toprule
Class & {Original} & {SMOTE-} \\
& & {Tomek} \\
\midrule
{0} & 11645 & 10444 \\
{1} & 618 & 10305 \\
{2} & 618 & 9976 \\ \addlinespace
{3} & 682 & 11597 \\
{4} & 736 & 10190 \\
{5} & 829 & 10462 \\
\bottomrule
\end{tabular}
\caption{Client 1 balance by SMOTE-Tomek}
\end{subtable}%
\hfill
\begin{subtable}{0.45\columnwidth}
\centering
\begin{tabular}{@{} l *{2}{S[table-format=5.0,group-four-digits=true]} @{}}
\toprule
Class& {Original} & {SMOTE-} \\
& & {Tomek} \\
\midrule
{0} & 11645 & 10444 \\
{1} & 618 & 10305 \\
{2} & 618 & 9976 \\ \addlinespace
{3} & 682 & 11597 \\
{4} & 736 & 10190 \\
{5} & 829 & 10462 \\
\bottomrule
\end{tabular}
\caption{Client 2 balance by SMOTE-Tomek}
\end{subtable}
\caption{principal}
\end{table}
\lipsum % filler text
\end{document}
答案2
与@Mico 答案(+1)类似,但使用包(版本 3.1)中定义的tabularray
和环境,并在最后一个表格列的列标题中手动断开文本:subfloat
subcaption
\documentclass[journal]{IEEEtran}
\usepackage{subcaption}
\captionsetup[subtable]{justification=centering} % optional
\usepackage{tabularray}
\UseTblrLibrary{booktabs, siunitx, varwidth}
\usepackage{lipsum} % for dummy text
\begin{document}
\begin{table}
\sisetup{table-format=5,
group-four-digits=true}
\centering
\subfloat[Client 1 balance by SMOTE-Tomek]%
{
\begin{tblr}{colspec={ c *{2}{Q[c,m, si]} },
measure=vbox
}
\toprule
Class & {{{Original}}} & {{{SMOTE-\\ Tomek}}} \\
\midrule
0 & 11645 & 10444 \\
1 & 618 & 10305 \\
2 & 618 & 9976 \\ \addlinespace
3 & 682 & 11597 \\
4 & 736 & 10190 \\
5 & 829 & 10462 \\
\bottomrule
\end{tblr}
}%
\hfil
\subfloat[Client 2 balance by SMOTE-Tomek]%
{
\begin{tblr}{colspec={ c *{2}{Q[c,m, si]} },
measure=vbox
}
\toprule
Class & {{{Original}}} & {{{SMOTE-\\ Tomek}}} \\
\midrule
0 & 11645 & 10444 \\
1 & 618 & 10305 \\
2 & 618 & 9976 \\ \addlinespace
3 & 682 & 11597 \\
4 & 736 & 10190 \\
5 & 829 & 10462 \\
\bottomrule
\end{tblr}
}%
\caption{principal}
\label{tab:principal}
\end{table}
\lipsum
\end{document}