多行對齊:第一行有兩張圖片,第二行有第三張圖片,呈方形

多行對齊:第一行有兩張圖片,第二行有第三張圖片,呈方形

我要顯示三張圖片,以三種不同的寬高比,我想對齊它們,以便前兩張圖片在第一行上具有相同的高度,第三張圖片具有前兩張圖片的寬度,以便它顯示為一個正方形。圖片比例為橫向 4/3,前兩張為縱向 16/9,第三張為橫向 16/9(以便您輕鬆拍照)。

我怎樣才能做到這一點?目前,我手動調整了寬度和高度,但我想要一種更自動的方式或使其與subfig.這是我的程式碼:

\begin{figure}[ht]

  \begin{minipage}{\textwidth}
    \begin{center}
      \includegraphics[height=7cm]{pic1}
      \includegraphics[height=7cm]{pic2}
    \end{center}
  \end{minipage}

  \quad

  \begin{minipage}{\textwidth}
    \begin{center}
      \includegraphics[width=15cm]{pic3}
    \end{center}
  \end{minipage}

\label{figpic}

\end{figure}

不太整潔的多行對齊範例

感謝您的幫助 !

答案1

神奇的數字是 91=64+27:

\documentclass{article}

\usepackage{subcaption}
\usepackage{graphicx}

\newlength{\preferredwidth}
\setlength{\preferredwidth}{12cm}

\begin{document}

\begin{figure}
\centering

\begin{subfigure}{\dimexpr\preferredwidth*64/91}
\includegraphics[width=\linewidth]{example-image-4x3}
\caption{Ratio 4:3 landscape}
\end{subfigure}%
\begin{subfigure}{\dimexpr\preferredwidth*27/91}
\includegraphics[width=\linewidth]{example-image-9x16}
\caption{Ratio 16:9 portrait}
\end{subfigure}

\medskip

\begin{subfigure}{\dimexpr\preferredwidth} 
\includegraphics[width=\linewidth]{example-image-16x9}
\caption{Ratio 16:9 landscape}
\end{subfigure}

\end{figure}

\end{document}

在此輸入影像描述

與壓縮在一起的影像相同:

\documentclass{article}

\usepackage{graphicx}

\newlength{\preferredwidth}
\setlength{\preferredwidth}{12cm}

\begin{document}

\begin{figure}
\centering

\includegraphics[width=\dimexpr\preferredwidth*64/91]{example-image-4x3}%
\includegraphics[width=\dimexpr\preferredwidth*27/91]{example-image-9x16}\\
\includegraphics[width=\preferredwidth]{example-image-16x9}

\end{figure}

\end{document}

在此輸入影像描述

假設左上角和右上角影像的比例為rs, 分別。如果首選寬度是w,那麼左圖像的寬度應該是讀寫/(r+s)和右圖像的寬度應該是SW/(r+s)。在你的情況下r= 4/3 和s= 9/16 這解釋了幻數 91 = 4·16 + 3·9。底部圖像對計算沒有影響,因此在任何情況下都不會得到正方形。

答案2

在此輸入影像描述

\documentclass{article}% always use a complete document not a fragment

\usepackage{graphicx}

\begin{document}

\begin{figure}[htp]% include p

%  \begin{minipage}{\textwidth} a \textwidth minipage does nothing
\centering%\begin{center}

% mwe package images
      \sbox0{\includegraphics[height=4cm]{example-image-a}% no word space
      \includegraphics[height=4cm]{example-image-4x3}}

%  \quad ????

      \usebox{0}\\
      \includegraphics[width=\wd0]{example-image-a3-landscape}


\label{figpic}

\end{figure}

\end{document}

相關內容