2

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.
<to be read again> 
                   \let 
l.72        \includegraphics
                       [width=5cm]{initial_uniform.eps}

! Illegal unit of measure (pt inserted).
<to be read again> 
                   \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.

2

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}

enter image description here

  • 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

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.