126

I am using the following code to put my two figures side by side with different captions,

\begin{figure*}[t!]
    \centering
    \begin{subfigure}[b]{0.5\textwidth}
        \centering
        \includegraphics[height=1.2in]{a}
        \caption{Lorem ipsum}
    \end{subfigure}%
    ~ 
    \begin{subfigure}[b]{0.5\textwidth}
        \centering
        \includegraphics[height=1.2in]{b}
        \caption{Lorem ipsum, lorem ipsum,Lorem ipsum, lorem ipsum,Lorem ipsum}
    \end{subfigure}
    \caption{Caption place holder}
\end{figure*}

I get the following output: output

However, I want to position both my images vertically same line, like the following:

Desired output: desired

Sait
  • 2,007
  • 6
    IJust curious: Why are you using the "starred" version of the figure environment? Is your document maybe being typeset in twocolumn mode? If so, the only place where LaTeX will place a double-wide float is at the top of the page, which would make the [t!] location specifier unnecessary. – Mico Jun 19 '13 at 12:58
  • 2
    @Mico, yes. I was using a document in twocolumn mode. In MWE, I should have deleted that part, sorry. – Sait Jun 20 '13 at 14:15
  • 20
    Can @Sait show the usepackages please? – Gennaro Arguzzi Dec 06 '17 at 10:09

1 Answers1

174

Use the t option for the alignment of the subfigures:

\usepackage{subcaption}
\begin{figure*}[t!]
    \centering
    \begin{subfigure}[t]{0.5\textwidth}
        \centering
        \includegraphics[height=1.2in]{a}
        \caption{Lorem ipsum}
    \end{subfigure}%
    ~ 
    \begin{subfigure}[t]{0.5\textwidth}
        \centering
        \includegraphics[height=1.2in]{b}
        \caption{Lorem ipsum, lorem ipsum,Lorem ipsum, lorem ipsum,Lorem ipsum}
    \end{subfigure}
    \caption{Caption place holder}
\end{figure*}

Using this, both images will be aligned on top:

enter image description here

Suuuehgi
  • 887
  • 4
  • 18
latex user
  • 2,059
  • 2
    ...or as an alternative use the \captionbox command instead of the subfigure environment. \captionboxes will be aligned by the first line of the caption automatically. –  Jun 19 '13 at 19:16
  • 28
    Which pkg is required to use subfigure? – hhh Jul 15 '16 at 16:15
  • 51
    The subcaption package is the one for that :) – latex user Jul 20 '16 at 12:30
  • 7
    What's the meaning of "~"? – skan Nov 16 '17 at 22:42
  • 7
    @skan It's a non-breaking space. The subfigures don't stay next to each other when there is an empty line between them, so the space was added. Alternatively you could omit that line – it would just give you different horizontal spacing between the subfigures. – V02460 Nov 26 '17 at 15:49
  • 5
    what is figure*? – Hao S Oct 09 '19 at 21:08
  • Can I know what is there options of the alignment of subfigure? beside b, t? Is there a list to check all the options? – aan Jan 01 '20 at 11:51
  • 1
    @Hao S (3 years later) the starred version * of the figure environment (i.e. figure*) is for displaying a figure across the total width of the page when using a two-column document (see this answer). – zetyty Mar 04 '22 at 08:05
  • @aan You can find a list in the subcaption manual on CTAN, for e.g. section 3 (p. 6 of manual version 1.5 2022-02-20) with subcation v1.2: "Beside the outer-pos values of ‘c’, ‘t’, and ‘b’, the subcaption package also offers the values ‘T’ and ‘B’ additionally which align the subfigure at the very top resp. bottom. (In contrast ‘t’ and ‘b’ align the subfigure at the top resp. bottom baseline.)" – zetyty Mar 04 '22 at 08:22
  • Note also the percent symbol % on the line just before the non-breaking space ~. This is critical - without it, you'll get a line break between the subfigures and they'll appear top and bottom. – Josh Milthorpe Jan 24 '24 at 05:06
  • If I copy and paste this code into Overleaf and just change the filenames for the figures, then it gives me the images stacked atop each other. It also gives the subfigure captions as normal captions. I have downloaded the subcaption.sty file and added it to my Overleaf document. Can anyone explain this issue? – Mjoseph Mar 06 '24 at 16:48