1

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 A]{\includegraphics[width=0.45\linewidth]{example-image-a}}\quad
        \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:

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?

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

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):

enter image description here

In your case:

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

\begin{document}

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

\end{document}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.