2
\documentclass{article}

\begin{figure}[!] 
        \centering
        \begin{subfigure}[b]{0.24\textwidth}
                \centering
                \includegraphics[width=\textwidth]{1.eps}
                \caption{1}
                \label{fig:1 is 0}
        \end{subfigure}%
        \hfill 
        \begin{subfigure}[b]{0.24\textwidth}
                \centering
                \includegraphics[width=\textwidth]{2}
                \caption{2}
                \label{fig:2 is the life like}
        \end{subfigure}
        \hfill
        \begin{subfigure}[b]{0.24\textwidth}
                \centering
                \includegraphics[width=\textwidth]{3}
                \caption{3}
                \label{fig:3 is what people and the world like}
        \end{subfigure}
        \hfill
        \begin{subfigure}[b]{0.24\textwidth}
                \centering
                \includegraphics[width=\textwidth]{4}
                \caption{4}
                \label{fig:4 is what the earth and the mars like}
        \end{subfigure}

\end{figure}


\end{document}
Vivian
  • 647

1 Answers1

2

In this case, use the \subcaptionbox command, instead of subfigure; \subcaptionbox automatically aligns the subfigures by their very first caption line.

Here's a comparison showing the different vertical alignment obtained when using the subfigure environment and the \subcaptionbox command:

\documentclass{article}
\usepackage[demo]{graphicx}
\usepackage{subcaption}

\begin{document}

\begin{figure}
        \centering
        \begin{subfigure}[b]{0.24\textwidth}
                \centering
                \includegraphics[width=\textwidth]{1.eps}
                \caption{short}
                \label{fig:1}
        \end{subfigure}%
        \hfill 
        \begin{subfigure}[b]{0.24\textwidth}
                \centering
                \includegraphics[width=\textwidth]{2}
                \caption{short text}
                \label{fig:2}
        \end{subfigure}%
        \hfill
        \begin{subfigure}[b]{0.24\textwidth}
                \centering
                \includegraphics[width=\textwidth]{3}
                \caption{a little longer text}
                \label{fig:3}
        \end{subfigure}%
        \hfill
        \begin{subfigure}[b]{0.24\textwidth}
                \centering
                \includegraphics[width=\textwidth]{4}
                \caption{a much longer text goes here}
                \label{fig:4}
        \end{subfigure}
\caption{a general caption}
\label{fig:testa}
\end{figure}

\begin{figure}
\centering
\subcaptionbox{short\label{fig:11}}{\includegraphics[width=.24\linewidth]{1.eps}}\hfill 
\subcaptionbox{short text\label{fig:22}}{\includegraphics[width=.24\linewidth]{2.eps}}\hfill
\subcaptionbox{a little longer text\label{fig:33}}{\includegraphics[width=.24\linewidth]{3.eps}}\hfill
\subcaptionbox{a much longer text goes here\label{fig:44}}{\includegraphics[width=.24\linewidth]{4.eps}}
\caption{a general caption}
\label{fig:testb}
\end{figure}

\end{document}

enter image description here

The demo option for graphicx simply replaces actual figures with black rectangles; do not use that option in your actual document.

Gonzalo Medina
  • 505,128
  • @ I use [!] to make the figures do not run to far away places. And if the captions have different length, the figures are not on a line. How could align the captions on their top to make the figures on a line from the bottom. – Vivian Sep 03 '13 at 14:58
  • @Vivian as I said. [!] is not a valid placement specifier. You should use a valid option like [!ht], [!bt], or nothing at all. – Gonzalo Medina Sep 03 '13 at 15:00
  • @Vivian please see my updated answer. – Gonzalo Medina Sep 03 '13 at 15:07
  • Thank you so much. I still have to add a overall caption which is number. I try to add a \caption{} but do not work. So would you tell me should I add a overall caption? – Vivian Sep 03 '13 at 15:20
  • @Vivian you're welcome! See my updated answer. Also, don't forget that you can accept the answer (if you consider it solved your problem) by clicking the checkmark to its left. In case of doubt, please see How do you accept an answer?. – Gonzalo Medina Sep 03 '13 at 15:29
  • @ Yes, of course. This is the right answer. This really help me. – Vivian Sep 03 '13 at 15:34