[Tex/LaTex] Fill \textwidth with equal-height subfigures of different aspect ratios

heightsubcaptionwidth

I would like two subfigures to have the same height and fill out the available \textwidth (with some margin between them).

How can I get the left subfigure to have the height of the right subfigure while preserving aspect ratio? I'd also like to keep the whitespace between the subfigures at something like 5%.

\documentclass{article}
\usepackage{mwe}
\usepackage{subcaption}
\usepackage[export]{adjustbox}
\begin{document}
\blindtext
\begin{figure}
    \begin{subfigure}{0.3\textwidth}
        \includegraphics[max width=\linewidth]{example-image-9x16}
    \end{subfigure}
    \hfill
    \begin{subfigure}{0.65\textwidth}
        \includegraphics[max width=\linewidth]{example-image-16x9}
    \end{subfigure}
    \caption{Two subfigures of the same height}
\end{figure}

\end{document}

Best Answer

For a manual solution I suggest the following steps:

  1. comment the subfigure environment for now
  2. Specify the same fixed height for both figures
  3. Play around with this value until the distance between both figures is approx. 5%
  4. insert the subfigure environments again and either have a look at the log file from the previous run to find out the size of the include images or just play around with the widths of the sub figure environments starting from two small and enlarge them until any overfull box warnings vanished.

\documentclass{article}
\usepackage{mwe}
\usepackage{subcaption}
\usepackage[export]{adjustbox}
\begin{document}
\blindtext
\begin{figure}
    \begin{subfigure}{0.24\textwidth}%
        \includegraphics[height=5cm]{example-image-9x16}%
    \end{subfigure}%
    \hfill%
    \begin{subfigure}{0.74\textwidth}%
        \includegraphics[height=5cm]{example-image-16x9}%
    \end{subfigure}%
    \caption{Two subfigures of the same height}
\end{figure}

\end{document}

enter image description here