[Tex/LaTex] My table is not conforming to the IEEEtran caption table format

captionsieeetrantables

I have the following code which produces the first attached Table. But as you can see in the table, both the table label and the caption all fall on the same line:

\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}

enter image description here

But what I want is a table with the caption format below:

enter image description here

How do I achieve this? Any help will be appreciated.

Best Answer

  • cause of your problem is package subcaption. do you really need them? if not simple delete it and your problem will disappear
  • if you need subcaption than you need mimic IEEEtran table caption set up already in document preamble (see mwe below)

off-topic:

  • resize table to 0.5\textwidth is not good solution. with this the table is wider then text in a column. if you persist to resize table, then: \resizebox{\columnwidth}{!}{....}
  • instead of resizing is better redesign a table to fit column width (see mwe below)

enter image description here

\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}

note: in preamble i delete all packages load twice and comment others not relevant to this mwe