*NIX Tricks

[latex] Multiple figures under the same caption using ``subfigure''

Posted in latex by kousik on November 9, 2009

If you want to put several small figures under the same caption, then you need to include the subfigure (along with  graphicx) package. The format is something like this:

%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%            Contents of main.tex (LaTeX Source)                                                                          
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
%%%%%%%%%   Preamble %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
\documentclass[11pt,a4paper]{article}
\usepackage{graphicx, subfigure}
%
%%%%%%%%% The Document starts here  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
\begin{document}
%
Some random text at the beginning of the document ........
%%
% --------------  Include the figures as follows -------------------%
%%
\begin{figure}[ht!]
     \begin{center}
%
        \subfigure[Caption of First Figure]{%
            \label{fig:first}
            \includegraphics[width=0.4\textwidth]{FirstFigure}
        }%
        \subfigure[Caption of Second Figure]{%
           \label{fig:second}
           \includegraphics[width=0.4\textwidth]{SecondFigure}
        }\\ %  ------- End of the first row ----------------------%
        \subfigure[Caption of Third Figure]{%
            \label{fig:third}
            \includegraphics[width=0.4\textwidth]{ThirdFigure}
        }%
        \subfigure[Caption of Fourth Figure]{%
            \label{fig:fourth}
            \includegraphics[width=0.4\textwidth]{FourthFigure}
        }%
%
    \end{center}
    \caption{%
        The l-o-n-g caption for all the subfigures
        (FirstFigure through FourthFigure) goes here.
     }%
   \label{fig:subfigures}
\end{figure}
%%
% -------------- End of figure environment ----------------------%
%%

The first, second, third and the fourth subfigures in  Figure
\ref{fig:subfigures} are labeled as
\ref{fig:first}, \ref{fig:second}, \ref{fig:third} and \ref{fig:fourth},
respectively.

Some more text before the end ..........
%
\end{document}
%
%%%%%% The End %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

It will create two rows of subfigures with two subfigures on each row (needless to say, you must have all those figures, viz. FirstFigure.eps through FourthFigure.eps, in the same directory as the LaTeX source file). The optional argument within the square brackets immediately following the subfigure statement is the caption of the subfigure (besides the main caption for all the subfigures at the end).

Various other options (e.g., cropping, resizing are rotating the figures) for includegraphics were explained awhile ago.

Reference: here.

7 Responses

Subscribe to comments with RSS.

  1. [...] More about includegraphics was posted awhile ago: here and here. [...]

  2. [...] More about includegraphics was posted awhile ago: here and here. [...]

  3. Gula Kapas said, on May 12, 2011 at 11:38 AM

    when i compile, i get the error:
    File “subfigure.sty” not found

    • kousik said, on May 14, 2011 at 3:09 AM

      This error indicates that you don’t have the required style file “subfigure.sty” in the LaTeX search path. As a temporary solution, you may download the subfigure.sty in your working directory and the compile your LaTeX document. (Copy subfigure.sty to the correct directory where all other style file resides to make this solution ‘permanent’!)

      Download location in the CTAN archive:
      http://www.ctan.org/tex-archive/obsolete/macros/latex209/contrib/misc

  4. rob said, on May 19, 2011 at 10:22 AM

    Thanks, this was a big help.

  5. giorgio said, on February 11, 2012 at 12:02 PM

    HI all, I think that the general label referring to the whole figure must be placed after the caption (that is, \label{fig:subfigures} must go just before \end{figure})
    otherwise latex won’t show the good figure number..
    giorgio

    • kousik said, on February 22, 2012 at 9:43 AM

      You are absolutely right. Thanks! I have fixed the problem.


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.