
假設我們有兩個寬度不同的圖像。現在我們想要將它們彼此相鄰對齊,但高度相同。
最小工作範例(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}
結果截圖:
問題說明:
只要兩個影像具有相同的寬度和高度,上部 MWE 就可以完全正常運作。
然而,就我而言,我有兩個高度相同但寬度不同的圖像。我如何聲明兩個圖像應採用相同的高度,同時自行調整其必要的寬度?
在過去,我嘗試過一些事情,[width=0.457585\linewidth]
直到我將它們放大到(或多或少)相似的高度,這是一種令人討厭的方法。
我想有更好的選擇可以做到這一點嗎?
答案1
該graphicx
包還允許您設定圖像的高度(以及許多其他參數)。這裡有一些可能的參數的列表(來自包文檔):
在你的情況下:
\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}