5

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.

2
  • \captionsetup{justification=centering, labelsep=newline} Aug 19, 2017 at 2:32
  • Thanks, @JohnKormylo, your suggestion solved the problem.
    – obiigbe91
    Aug 19, 2017 at 2:40

2 Answers 2

5
  • 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

1
  • For me, this captionsetup didn't quite get me to the IEEEtran journal format. I had to use \captionsetup[table]{textfont={sc,footnotesize}, labelfont=footnotesize, labelsep=newline}. But thanks for the tip on labelsep!
    – Praveen
    Aug 20, 2018 at 2:29
1

Based on @John Kormylo's comment, I inserted the code \captionsetup{justification=centering, labelsep=newline} inside the table, as shown below, and it solved the problem.

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

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.