2

Code:

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

\begin{document}
\begin{figure}[H]
    \centering
    \begin{subfigure}{0.5\textwidth}
        \includegraphics[width=6cm]{initial_normal.eps}
        \caption{Normal Distribution}
        \label{fig1a}
    \end{subfigure}%
    \begin{subfigure}{0.5\textwidth}[H]
        \includegraphics[width=6cm]{initial_uniform.eps}
        \caption{Uniform Distribution}
        \label{fig1b}
    \end{subfigure}
\caption{distributions}
\end{figure}
\end{document}

The captions should come below the figure but I am getting them to the right of the figures and the caption text is aligned centrally with respect to the page instead of the subfigure. Am I making a mistake here?

3

You should not put [H] after \begin{subfigure}{\textwidth}[H] Further, these points may be noted:

  1. Don't put a blank line in between the subfigures.
  2. The sum of widths of two subfigure should not exceed \textwidth
  3. Put a % after the first subfigure if you specify a width of 0.5\textwidth for both subfigures. If the sum is less than \textwidth, you may put a \hfill in between.

Now your code:

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

\begin{document}
\begin{figure}[H]
%    \centering
    \begin{subfigure}{0.5\textwidth}
        \centering
        \includegraphics[width=6cm]{initial_normal.eps}
        \caption{Normal Distribution}
        \label{fig1a}
    \end{subfigure}%   %% This % is needed when you use 0.5\textwidth
    %  Don't leave the blank line
    \begin{subfigure}{0.5\textwidth}%[H]   %% Don't put this here
        \centering
        \includegraphics[width=6cm]{initial_uniform.eps}
        \caption{Uniform Distribution}
        \label{fig1b}
    \end{subfigure}
\end{figure}
\end{document}

enter image description here

May be the subcaption package manual is useful here. You can access it by typing texdoc subcaption from command line/prompt. The correct usage for subfigure is

\begin{subfigure}[<pos>]{<width>}

... content like \includegraphics and caption

\end{subfigure}

Here <pos> is t or b c (default). Both [<pos>]{<width>} are same as that for a minipage.

  • still doesnt work – WYSIWYG Aug 12 '14 at 9:01
  • See even in your case the the subfigure caption is not directly below the subfigure.. Mine is worse still; I am not getting the neat composite figure as shown in all the examples. No difference in my code!! – WYSIWYG Aug 12 '14 at 9:03
  • @bharat_iyengar Where do you want the caption? Both figure and caption centered or left aligned? – user11232 Aug 12 '14 at 9:05
  • Figures side by side and their captions centrally aligned with respect to the subfigure (not the page). Just like this – WYSIWYG Aug 12 '14 at 9:07
  • thanks harish.. i made an edit.. the captions are still not quite in their position. And what is the logic of putting a % after \end{subfigure} – WYSIWYG Aug 12 '14 at 9:25

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.