# Subfloat: How to align two images with different width to same height?

Assumed we have two images with different widths. Now we want to align them next to each other, but with same height.

Minimum working example (MWE):

\documentclass{article}
\usepackage{graphicx}
\usepackage{subfig}

\begin{document}

\begin{figure}[h]
\centering
\subfloat[Picture B]{\includegraphics[width=0.45\linewidth]{example-image-b}}\\
\captionsetup{justification=justified,margin=1cm}
\caption{Comparison of steady state results (a)~x method (b)~y method}
\end{figure}

\end{document}


Screenshot of the result:

Description of the issue:

The upper MWE is working completely fine as long as both images have the same width and same height.

However, in my case I have two images with same height but different width. How can I declare that both images should adopt the same height while adjusting their necessary width by themselves?

In the past I played around with things like [width=0.457585\linewidth] until I scaled them up to (more or less) similar heights what is a annoying approach.

I guess there is some better option available to do so?

• Have you tried \includegraphics[height = ...]{...}? Feb 28, 2019 at 18:24
• @zetaeffe: Pleaes post this as an answer. :-)
– Dave
Mar 2, 2019 at 12:09

The graphicx package allows you also to set the height of the image (among many other parameters). Here there's a list of some of the possibile parameters (from the package documentation):

\documentclass{article}
\usepackage{graphicx}
\usepackage{subfig}

\begin{document}

\begin{figure}[h]
\centering