# Control errors with subcaption subfigure

Code:

\documentclass[fleqn,11pt,a4paper]{article}
\usepackage{geometry,array,graphicx,float,caption}
\usepackage{subcaption}

\begin{document}
\begin{figure}[H]
\centering
\begin{subfigure}
\includegraphics[width=5cm]{initial_uniform.eps}
\caption{Uniform Distribution}
\label{fig1a}
\end{subfigure}
\end{figure}


I have the caption package installed and subcaption.sty is detected. However, when I use subfigure I am getting these errors:

! Missing number, treated as zero.
\let
l.72        \includegraphics
[width=5cm]{initial_uniform.eps}

! Illegal unit of measure (pt inserted).
\let
l.72        \includegraphics
[width=5cm]{initial_uniform.eps}


and more control errors.

When I comment out the lines for begin and end subfigure i.e use just normal figure, everything works just fine. I can't understand what is wrong here.

Your usage of subfigure is missing the width. Use

\begin{subfigure}{0.5\textwidth}


Second mandatory argument is the width of the sub figure.

Your code with this correction is

\documentclass[fleqn,11pt,a4paper,demo]{article}   %% remove demo
\usepackage{geometry,array,graphicx,float,caption}
\usepackage{subcaption}

\begin{document}
\begin{figure}[H]
\centering
\begin{subfigure}{0.5\textwidth}
%\centering  %% may be you need this
\includegraphics[width=5cm]{initial_uniform.eps}
\caption{Uniform Distribution}
\label{fig1a}
\end{subfigure}
\end{figure}
\end{document}


• I am sorry.. I did write [width=5cm] some mistake while pasting i guess. I tried both width and scale. But setting subfigure width fixed the issue. I didn't know that was necessary. Thanks – WYSIWYG Aug 12 '14 at 8:25
• @bharat_iyengar Oh! OK. I modified the answer. – user11232 Aug 12 '14 at 8:27
• One more thing. My captions are coming on the left side of the figure instead of bottom. How to fix it? – WYSIWYG Aug 12 '14 at 8:33
• @bharat_iyengar Can you show the code that produces this undesired effect? – user11232 Aug 12 '14 at 8:36
• It is the same as I posted. Plus the subfigures are not aligned side by side. They are stacked. Perhaps because of the side captions. – WYSIWYG Aug 12 '14 at 8:38