[Tex/LaTex] Forcing subfigures to have same height and take overall X% of linewidth in LaTeX

floats

I want to make a figure composed of two images that have different sizes. I want to put them side by side so that they have the same height and that they overall take, say, 90% of the line width.

It is easy to make them have the same fixed height (say in cm), but how to let this common height be automatically adjusted to fulfill the desired overall width? Manual trial-and-error is time-consuming, approximate and non robust.

A solution with or without subfigure or another LaTeX package is OK.

Best Answer

You can include them to the same (more or less arbitrary) height then scale them together to the desired width

enter image description here

\documentclass{article}

\usepackage{graphicx}% images from mwe package

\begin{document}

\noindent X\dotfill X

\begin{center}
\resizebox{.9\textwidth}{!}{%
\includegraphics[height=3cm]{example-image-a}%
\quad
\includegraphics[height=3cm]{example-image-16x9}%
}
\end{center}

\end{document}