# Global caption issue with table when using subcaption package

Firstly I apologize if this had been answered before. I have tried looking for it anywhere but I couldn't find any solution.

Anyway, I have a trouble with the caption of my table when I included the subcaption package.

This is the excerpt of the code:

    \documentclass{ifacconf}
\usepackage{natbib}
\usepackage{graphicx}
\usepackage{subcaption}

\begin{document}

\begin{table}[hb]
\centering
\caption{Test eheh blah}
\begin{tabular}{|c|c|c|c|} \hline
\multicolumn{4}{|c|}{Margin settings} \\
\hline
Page & Top & Bottom & Left/Right \\ \hline
First & 3.5 & 2.5 & 1.5 \\ \hline
Rest & 2.5 & 2.5 & 1.5 \\ \hline
\end{tabular}
\end{table}

\end{document}


And the output is

withSubcaption http://imageshack.com/scaled/800x600/513/0o0l.jpg

However, if I removed the subcaption package, the output is as expected

withoutSubcaption http://imageshack.com/scaled/800x600/513/75c3.jpg

So, I would really appreciate any help. Thanks.

Cheers.

EDITED:

Following Harish Kumar answer, although it does solve the caption issue in my table, it causes problem in the captions of my other subfigure. Here is the code of the subfigure.

    \usepackage{epstopdf}
\begin{figure}[htb!]
\centering
\begin{subfigure}{0.38\textwidth}
\centering
\includegraphics[width=\textwidth]{pic1.eps}
\caption{test caption}
\label{fig:pic1}
\end{subfigure}
\\
\begin{subfigure}{0.38\textwidth}
\centering
\includegraphics[width=\textwidth]{pic2.eps}
\caption{test caption}
\label{fig:pic2}
\end{subfigure}
\caption{Long caption Long caption.}
\label{fig:pictures}
\end{figure}


And the output

subfigure http://imageshack.com/scaled/800x600/534/7ufa.jpg

• Welcome to TeX.SX! You can have a look at our starter guide to familiarize yourself further with our format. – user11232 Oct 10 '13 at 0:17
• Where we can find ifacconf.cls? – user11232 Oct 10 '13 at 0:17
• IFAC Latex template. That's interesting, if I use \documentclass[a4paper, 12pt]{article} instead, the output is as expected. – Ron Oct 10 '13 at 0:29

The ifacconf class is not compatible with caption, as the warning

Package caption Warning: Unsupported document class (or package) detected,
(caption)                usage of the caption package is not recommended.
See the caption package documentation for explanation.


tells you. This means that also subcaption cannot be used.

In these cases, the good old subfig package usually comes to the rescue, but there's a catch: the class defines \captionwidth as a command, whereas subfig defines it as a dimension register. Moreover, the class wrongly does

\let\endfigure\end@float
\let\endtable\end@float


This makes the class incompatible with subfig too.

Workaround:

\documentclass{ifacconf}
\usepackage{natbib}
\usepackage{graphicx}

\makeatletter
\def\endfigure{\end@float}
\def\endtable{\end@float}
\makeatother

\let\ifacconfcaptionwidth\captionwidth
\usepackage[caption=false]{subfig}
\let\captionwidth\ifacconfcaptionwidth

\begin{document}

\begin{table}[htbp]

\centering
\caption{Test eheh blah}
\begin{tabular}{|c|c|c|c|} \hline
\multicolumn{4}{|c|}{Margin settings} \\
\hline
Page & Top & Bottom & Left/Right \\ \hline
First & 3.5 & 2.5 & 1.5 \\ \hline
Rest & 2.5 & 2.5 & 1.5 \\ \hline
\end{tabular}

\end{table}

\begin{table}[htbp]

\centering
\caption{Test eheh blah}

\subfloat[A subcaption]{%
\begin{tabular}{|c|c|c|c|} \hline
\multicolumn{4}{|c|}{Margin settings} \\
\hline
Page & Top & Bottom & Left/Right \\ \hline
First & 3.5 & 2.5 & 1.5 \\ \hline
Rest & 2.5 & 2.5 & 1.5 \\ \hline
\end{tabular}%
}

\subfloat[B subcaption]{%
\begin{tabular}{|c|c|c|c|} \hline
\multicolumn{4}{|c|}{Margin settings} \\
\hline
Page & Top & Bottom & Left/Right \\ \hline
First & 3.5 & 2.5 & 1.5 \\ \hline
Rest & 2.5 & 2.5 & 1.5 \\ \hline
\end{tabular}%
}

\end{table}

\end{document}


So long as you don't use subfig options to change the appearance of the subcaptions, this should be sufficient.

A perhaps better workaround might be

\documentclass{ifacconf}
\usepackage{natbib}
\usepackage{graphicx}

\makeatletter
\def\endfigure{\end@float}
\def\endtable{\end@float}
\makeatother

\usepackage[caption=false]{subfig}
\usepackage{etoolbox}

\AtBeginEnvironment{figure}{\setlength{\captionwidth}{0.8\linewidth}}
\AtBeginEnvironment{table}{\setlength{\captionwidth}{0.8\linewidth}}
\captionsetup[subfloat]{width=.7\captionwidth}

\begin{document}

\begin{table}[htbp]

\centering
\caption{Test eheh blah}
\begin{tabular}{|c|c|c|c|} \hline
\multicolumn{4}{|c|}{Margin settings} \\
\hline
Page & Top & Bottom & Left/Right \\ \hline
First & 3.5 & 2.5 & 1.5 \\ \hline
Rest & 2.5 & 2.5 & 1.5 \\ \hline
\end{tabular}

\end{table}

\begin{table}[htbp]

\centering
\caption{Test eheh blah}

\subfloat[A subcaption]{%
\begin{tabular}{|c|c|c|c|} \hline
\multicolumn{4}{|c|}{Margin settings} \\
\hline
Page & Top & Bottom & Left/Right \\ \hline
First & 3.5 & 2.5 & 1.5 \\ \hline
Rest & 2.5 & 2.5 & 1.5 \\ \hline
\end{tabular}%
}

\subfloat[B subcaption]{%
\begin{tabular}{|c|c|c|c|} \hline
\multicolumn{4}{|c|}{Margin settings} \\
\hline
Page & Top & Bottom & Left/Right \\ \hline
First & 3.5 & 2.5 & 1.5 \\ \hline
Rest & 2.5 & 2.5 & 1.5 \\ \hline
\end{tabular}%
}

\end{table}

\end{document}


but my advice is “don't use subfloats with this class”.