5

There are some threads about subfigures and alignment, but I could not find a solution for my problem. I want to have two figures side by side, both with their own capture (a and b) and below one capture for both. Using

\documentclass{article}
\usepackage{subcaption}
\usepackage{graphicx}

\begin{document}
\begin{figure}
    \centering
    \begin{subfigure}[b]{.49\textwidth}
        \centering
        \includegraphics[width=6cm]{example-image-a}
        \caption{Caption describing fig a}
        \label{fig:figure_a}
    \end{subfigure}\hfill%
    \begin{subfigure}[b]{.49\textwidth}
        \centering
        \includegraphics[width=7cm]{example-image-b}
        \caption{Caption describing fig b}
        \label{fig:figure_b}
    \end{subfigure}
    \caption{Caption for both images}
    \label{fig:Filter_L_LCL}
\end{figure}
\end{document}

gives me this: enter image description here

and using my graphics I get this, so it is quite the similar situation:

enter image description here

Exactly what I want, expect the image alignment. I'd like to have them top-aligned and captions bottom-aligned (the image size must not be changed since image and document font size match). How can this be done? Any solution without manually shifting?

  • 2
    Welcome to TeX.SX! You should edit your question to make your code a complete compilable minimal working example (MWE) beginning at \documentclass and ending at \end{document} providing all we need to compile it and reproduce your issue/error, but nothing more. For images you should use example-image in \includegraphics. – Skillmon Sep 05 '17 at 18:15
  • 1
    https://tex.stackexchange.com/questions/152818/top-aligned-subfigure-with-bottom-aligned-caption looks like a duplicate of your question, does any of the answers there help? – Torbjørn T. Sep 05 '17 at 18:42
  • 1
  • This seems to come up a lot: see also https://tex.stackexchange.com/questions/331118/how-do-i-align-both-baseline-and-caption-in-a-horizontal-tikzpicture-subcaption – John Kormylo Sep 05 '17 at 20:49

3 Answers3

5

You can obtain it with the floatrow package:

\documentclass{article}
\usepackage{geometry}
\usepackage{subcaption}
\usepackage{graphicx, floatrow}

\begin{document}

\begin{figure}
\floatsetup{valign=t, heightadjust=all}
\ffigbox{%
\begin{subfloatrow}
\ffigbox{\includegraphics[width=6cm]{example-image-a}}{\caption{Caption describing fig a \label{fig:figure_a}}}
\ffigbox{\includegraphics[width=7cm]{example-image-b}}{\caption{Caption describing fig b} \label{fig:figure_b}}
    \end{subfloatrow}}
    {\caption{Caption for both images}
    \label{fig:Filter_L_LCL}}
\end{figure}

\end{document} 

enter image description here

Bernard
  • 271,350
3

Move the shorter image into position using \raisebox:

enter image description here

\documentclass{article}

\usepackage{subcaption,graphicx}

\newsavebox{\tempfig}

\begin{document}

\begin{figure}
  \centering
  \begin{subfigure}[b]{.49\textwidth}
    \centering
    \savebox{\tempfig}{\includegraphics[width=7cm]{example-image-b}}% Store larger image in box
    \raisebox{\dimexpr\ht\tempfig-\height}{\includegraphics[width=6cm]{example-image-a}}
    \caption{Caption describing fig a}
  \end{subfigure}\hfill%
  \begin{subfigure}[b]{.49\textwidth}
    \centering
    \includegraphics[width=7cm]{example-image-b}
    \caption{Caption describing fig b}
  \end{subfigure}
  \caption{Caption for both images}
\end{figure}

\end{document}

The height of the raise is given by the difference between the height of the larger image (\ht\tempfig, where \tempfig is the box containing the larger image) and the smaller image (\height - the natural height of the element contained within \raisebox's second argument).

Werner
  • 603,163
0

I would suggest using similar code: (pay attention to "\usepackage[export]{adjustbox}" and " valign=t"

\documentclass{eage2024}
\usepackage{subcaption}
\usepackage{graphicx}
\usepackage[export]{adjustbox}

\begin{document}

\begin{figure}[!tbp] \centering \begin{subfigure}[b]{0.2\textwidth} \includegraphics[width=1\textwidth, valign=t]{8a.png} \caption{cc.} \label{fig:h1} \end{subfigure} \begin{subfigure}[b]{0.2\textwidth} \includegraphics[width=1\textwidth, valign=t]{8b.png} \caption{cc2.} \label{fig:h2} \end{subfigure} \begin{subfigure}[b]{0.2\textwidth} \includegraphics[width=1\textwidth, valign=t]{8c.png} \caption{cc3.} \label{fig:h3} \end{subfigure} \begin{subfigure}[b]{0.2\textwidth} \includegraphics[width=1\textwidth, valign=t]{8d.png} \caption{Triple layer-thickness 1.} \label{fig:h4} \end{subfigure} \caption{cc4.} \label{fig:h5} \end{figure}

\end{document}

Mensch
  • 65,388
  • As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers in the help center. – Community Jan 07 '24 at 10:43
  • It would help to explain what your suggested changes are doing. – AlMa Jan 07 '24 at 16:25