[Tex/LaTex] Table Numbering And Caption in Same location

captionsformattingtablestabularx

My table and caption are located on the same line and this started happening after I used a different class file for the conference I am applying towards.

Here is a picture of what I mean:
(Normally the words "Table 1" go above the caption, not on the same line)
enter image description here

I was wondering what could be some reason for this? What should I look for in the class file to see if this was on purpose or my mistake?

Best Answer

The old document class differs from the new document class in how it defined \@makecaption - the macro responsible for setting the caption of floats. Here's the difference:

Old document class:

\long\def\@makecaption#1#2{%
  % test if is a for a figure or table
  \ifx\@captype\@IEEEtablestring%
    % if a table, do table caption
    \footnotesize\bgroup\par
      \centering\@IEEEtabletopskipstrut{\normalfont\footnotesize #1}\\
      {\normalfont\footnotesize\scshape #2}\par\addvspace{0.5\baselineskip}\egroup%
    \@IEEEtablecaptionsepspace
  % if not a table, format it as a figure
  \else
  %...
  \fi}

New document class:

\long\def\@makecaption#1#2{%
  % test if is a for a figure or table
  \ifx\@captype\@IEEEtablestring%
    % if a table, do table caption
    \footnotesize{\centering\normalfont\footnotesize#1.\qquad\scshape #2\par}%
    \@IEEEtablecaptionsepspace
  % if not a table, format it as a figure
  \else
  %...
  \fi}

It's obvious that the older class inserts a line break \\ while the newer uses .\qquad to separate the caption type and text. It suffices to use etoolbox to patch \@makecaption to insert a \par (paragraph break) instead of using .\qquad:

enter image description here

\documentclass{IEEEtran}
\usepackage{etoolbox}% http://ctan.org/pkg/etoolbox
\makeatletter
\patchcmd{\@makecaption}% <cmd>
  {.\qquad}% <search>
  {\par}% <replace>
  {}{}% <success><failure>
\makeatother
\begin{document}
\begin{table}
  \caption{Filled with some text}
\end{table}
\end{document}

\patchcmd{<cmd>}{<search>}{<replace>}{<success>}{<failure>} searches for <search> in <cmd> and replaces it with <replace>. If this search-and-replace is successful, <success> is executed, otherwise <failure> is.

Related Question