![我的表格不符合 IEEEtran 标题表格式](https://linux22.com/image/360453/%E6%88%91%E7%9A%84%E8%A1%A8%E6%A0%BC%E4%B8%8D%E7%AC%A6%E5%90%88%20IEEEtran%20%E6%A0%87%E9%A2%98%E8%A1%A8%E6%A0%BC%E5%BC%8F.png)
我有以下代码,可生成第一个附加表。但正如您在表中看到的,表标签和标题都位于同一行:
\documentclass[10pt,journal,compsoc]{IEEEtran}
% *** CITATION PACKAGES ***
%
\ifCLASSOPTIONcompsoc
% IEEE Computer Society needs nocompress option
% requires cite.sty v4.0 or later (November 2003)
\usepackage[nocompress]{cite}
\else
% normal IEEE
\usepackage{cite}
\fi
\usepackage{subcaption}
%\usepackage{subfig}
%\usepackage{subcaption}
\usepackage[draft]{graphicx}
\usepackage{algorithm,algpseudocode}
\usepackage{mathtools}
\usepackage{filecontents}
\usepackage{lipsum}
\usepackage[flushleft]{threeparttable}
\usepackage{cite}
\usepackage{amssymb}
\usepackage{algpseudocode}% http://ctan.org/pkg/algorithmicx
\usepackage{mathtools, cases}
\usepackage{amsmath,empheq}
\usepackage{eqparbox} % for the second example
\usepackage{verbatim}
\usepackage{varwidth}% http://ctan.org/pkg/varwidth
\usepackage{color}
\usepackage{xcolor}
\usepackage[export]{adjustbox}
\usepackage{multirow}
\newcommand{\meq}[2]{%
\eqmakebox[#1][s]{$\displaystyle#2$}%
}
% correct bad hyphenation here
\hyphenation{op-tical net-works semi-conduc-tor}
%\let\emptyset\varnothing
\begin{document}
\begin{table}[!bp]
\centering
\caption{Evaluation of overall performances on both datasets}
\label{tab:default}
\resizebox{0.5\textwidth}{!}{%
\begin{tabular}{|l|l|l|l|l|l|l|}
\hline
\multicolumn{7}{|c|}{Datasets} \\ \hline
\multicolumn{3}{|c|}{In-House} & \multicolumn{4}{c|}{NSL-KDD} \\ \hline
DR & ACC & FPR & K & DR & ACC & FPR \\ \hline
\multirow{8}{*}{99.75\%} & \multirow{8}{*}{99.72\%} & \multirow{8}{*}{0.06\%} & 1 & 90.53\% & 96.14\% & 0.00\% \\ \cline{4-7}
& & & 2 & 94.22\% & 97.65\% & 0.00\% \\ \cline{4-7}
& & & 3 & 95.47\% & 98.16\% & 0.00\% \\ \cline{4-7}
& & & 4 & 96.10\% & 98.41\% & 0.00\% \\ \cline{4-7}
& & & 5 & 96.48\% & 98.57\% & 0.00\% \\ \cline{4-7}
& & & 10 & 97.25\% & 98.87\% & 0.02\% \\ \cline{4-7}
& & & 20 & 97.57\% & 98.88\% & 0.22\% \\ \cline{4-7}
& & & 30 & 97.68\% & 98.40\% & 1.11\% \\ \hline
\end{tabular}%
}
\end{table}
\end{document}
但我想要的是一个具有以下标题格式的表格:
我该如何实现这一点?任何帮助都将不胜感激。
答案1
- 导致您问题的原因是软件包
subcaption
。您真的需要它们吗?如果不是,只需将其删除,您的问题就会消失 - 如果需要
subcaption
,您需要模仿文档序言中已经设置的 IEEEtran 表格标题(请参阅姆韦以下)
无关:
- 调整表格大小
0.5\textwidth
并不是好的解决方案。这样表格就会比列中的文本更宽。如果你坚持调整表格大小,那么:\resizebox{\columnwidth}{!}{....}
- 与其调整大小,不如重新设计表格以适应列宽(参见姆韦以下)
\documentclass[10pt,journal,compsoc]{IEEEtran}
% *** CITATION PACKAGES ***
\ifCLASSOPTIONcompsoc
% IEEE Computer Society needs nocompress option
% requires cite.sty v4.0 or later (November 2003)
\usepackage[nocompress]{cite}
\else
% normal IEEE
\usepackage{cite}
\fi
\usepackage{subcaption}
\captionsetup[table]{justification=centerlast,
labelsep=newline,
font=sf,
textfont=footnotesize}
\usepackage[draft]{graphicx}
%\usepackage{algorithm,algpseudocode}
%\usepackage{filecontents}
%\usepackage{amssymb}
%\usepackage{mathtools, cases, empheq}
%\usepackage{eqparbox} % for the second example
%\usepackage{verbatim}
%\usepackage{varwidth}% http://ctan.org/pkg/varwidth
%\usepackage{xcolor}
\usepackage[export]{adjustbox}
\usepackage{multirow, tabularx}
%\usepackage[flushleft]{threeparttable}
\newcommand{\meq}[2]{%
\eqmakebox[#1][s]{$\displaystyle#2$}%
}
% correct bad hyphenation here
\hyphenation{op-tical net-works semi-conduc-tor}
\usepackage{lipsum}
\begin{document}
\lipsum[11]
\begin{table}[ht]
\caption{Evaluation of overall performances on both datasets and more text and more text and more text and more text and more text and more text and more text}
\label{tab:default}
\centering
\renewcommand\arraystretch{1.2}
\begin{tabularx}{\columnwidth}{|*{7}{X |}}
\hline
\multicolumn{7}{|c|}{Datasets} \\ \hline
\multicolumn{3}{|c|}{In-House (\%)} & \multicolumn{4}{c|}{NSL-KDD (\%)} \\ \hline
DR & ACC & FPR & K & DR & ACC & FPR \\ \hline
\multirow{8}{*}{99.75} & \multirow{8}{*}{99.72} & \multirow{8}{*}{0.06} & 1 & 90.53\ & 96.14 & 0.00 \\ \cline{4-7}
& & & 2 & 94.22 & 97.65 & 0.00 \\ \cline{4-7}
& & & 3 & 95.47 & 98.16 & 0.00 \\ \cline{4-7}
& & & 4 & 96.10 & 98.41 & 0.00 \\ \cline{4-7}
& & & 5 & 96.48 & 98.57 & 0.00 \\ \cline{4-7}
& & & 10 & 97.25 & 98.87 & 0.02 \\ \cline{4-7}
& & & 20 & 97.57 & 98.88 & 0.22 \\ \cline{4-7}
& &
& 30 & 97.68 & 98.40 & 1.11 \\ \hline
\end{tabularx}%
\bigskip
original table:
\resizebox{0.5\textwidth}{!}{%
\begin{tabular}{|l|l|l|l|l|l|l|}
\hline
\multicolumn{7}{|c|}{Datasets} \\ \hline
\multicolumn{3}{|c|}{In-House} & \multicolumn{4}{c|}{NSL-KDD} \\ \hline
DR & ACC & FPR & K & DR & ACC & FPR \\ \hline
\multirow{8}{*}{99.75\%} & \multirow{8}{*}{99.72\%} & \multirow{8}{*}{0.06\%} & 1 & 90.53\% & 96.14\% & 0.00\% \\ \cline{4-7}
& & & 2 & 94.22\% & 97.65\% & 0.00\% \\ \cline{4-7}
& & & 3 & 95.47\% & 98.16\% & 0.00\% \\ \cline{4-7}
& & & 4 & 96.10\% & 98.41\% & 0.00\% \\ \cline{4-7}
& & & 5 & 96.48\% & 98.57\% & 0.00\% \\ \cline{4-7}
& & & 10 & 97.25\% & 98.87\% & 0.02\% \\ \cline{4-7}
& & & 20 & 97.57\% & 98.88\% & 0.22\% \\ \cline{4-7}
& & & 30 & 97.68\% & 98.40\% & 1.11\% \\ \hline
\end{tabular}%
}
\end{table}
\lipsum[1-7]
\end{document}
笔记: 在序言中我删除了所有加载两次的包并评论了其他与此无关的包姆韦
答案2
根据@John Kormylo 的评论,我\captionsetup{justification=centering, labelsep=newline}
在表格中插入了代码,如下所示,解决了这个问题。
\begin{table}[!bp]
\captionsetup{justification=centering, labelsep=newline}
\centering
\caption{Evaluation of overall performances on both datasets}
\label{tab:default}
\resizebox{0.5\textwidth}{!}{%
\begin{tabular}{|l|l|l|l|l|l|l|}
\hline
\multicolumn{7}{|c|}{Datasets} \\ \hline
\multicolumn{3}{|c|}{In-House} & \multicolumn{4}{c|}{NSL-KDD} \\ \hline
DR & ACC & FPR & K & DR & ACC & FPR \\ \hline
\multirow{8}{*}{99.75\%} & \multirow{8}{*}{99.72\%} & \multirow{8}{*}{0.06\%} & 1 & 90.53\% & 96.14\% & 0.00\% \\ \cline{4-7}
& & & 2 & 94.22\% & 97.65\% & 0.00\% \\ \cline{4-7}
& & & 3 & 95.47\% & 98.16\% & 0.00\% \\ \cline{4-7}
& & & 4 & 96.10\% & 98.41\% & 0.00\% \\ \cline{4-7}
& & & 5 & 96.48\% & 98.57\% & 0.00\% \\ \cline{4-7}
& & & 10 & 97.25\% & 98.87\% & 0.02\% \\ \cline{4-7}
& & & 20 & 97.57\% & 98.88\% & 0.22\% \\ \cline{4-7}
& & & 30 & 97.68\% & 98.40\% & 1.11\% \\ \hline
\end{tabular}%
}
\end{table}