[Tex/LaTex] How to put two images next to each other with a) and b) labels

captionsfloatssubfloats

I want to put two images next to each other and in order to do that I have written these code:

\begin{figure}[h]
\begin{minipage}{16pc}
\includegraphics[width=16pc]{P_1.eps}
\caption{\label{fig4} Caption of the first image.
\end{minipage}\hspace{2pc}%
\begin{minipage}{16pc}
\includegraphics[width=16pc]{P_2.eps}
\caption{\label{fig4} Caption of the second image.
\end{minipage}
\end{figure}

But in pdf I see

Figure 4: Caption of the first image. Figure 5: Caption of the second image.

How I can change it so that it was

Figure 4-a: Caption of the first image. Figure 4-b: Caption of the second image.

or

Figure 4.a: Caption of the first image. Figure 4.b: Caption of the second image.

Thanks!

Best Answer

You can use the subcaption package (a powerful companion to the caption package):

\documentclass{article}
\usepackage{caption}
\usepackage{subcaption}

\DeclareCaptionFormat{subfig}{\figurename~#1#2#3}
\DeclareCaptionSubType*{figure}
\captionsetup[subfigure]{format=subfig,labelsep=colon,labelformat=simple}

\begin{document}

\begin{figure}[!ht]
  \begin{subfigure}[b]{.5\linewidth}
    \centering
    \rule{4cm}{3cm}
    \caption{A subfigure}
    \label{fig:1a}
  \end{subfigure}%
  \begin{subfigure}[b]{.5\linewidth}
    \centering
    \rule{4cm}{3cm}
    \subcaption{Another subfigure}
    \label{fig:1b}
  \end{subfigure}
  \caption{A figure with two subfigures}
  \label{fig:1}
\end{figure}

\end{document}
Related Question