サブフィギュアを同じ高さに自動的に拡大縮小するにはどうすればいいですか?

サブフィギュアを同じ高さに自動的に拡大縮小するにはどうすればいいですか?

文書内に並べて配置する図がたくさんありますが、それらのサイズはすべてわずかに異なります (つまり、すべてが 4:3 形式などではありません)。

私が現在行っているのは、width=0.XX\textwidth両方の高さがほぼ同じになるまで微調整することです。

ここでサンプル コードを示します。私が実現したいのは、マクロなどを使用して、2 つの図を指定するだけで、自動的に同じ高さに拡大縮小され、1 行に収まるようにすることです。これは可能ですか? 可能であれば、その方法は?

編集: 画像に特定のサイズを指定しないのはなぜかと聞かれるので、コードはどれでも任意のアスペクト比の2つの画像。2つの画像を指定すると、コードはそれらを横に並べて収まるように拡大縮小します。そして同じ高さで、利用可能な水平方向のスペースを埋めます。

\documentclass{scrreprt}
\usepackage{subfig}
\usepackage{graphicx}
\begin{document}
    \chapter{Figures}
    \begin{figure}[h!]
        \centering
        \subfloat[Figure one]{%
            \centering\includegraphics[width=0.45\textwidth]{example-image-a}}
        \qquad
        \subfloat[Figure two with different side proportions]{%
            \centering\includegraphics[width=0.45\textwidth]{example-image-16x9}}
        \caption{How to get the two figures to same height (respecting proportions)?}
    \end{figure}
\end{document}

私が得るもの:

私が得るもの

自動的に起こることを望むこと:

私が得たいもの

答え1

2 つのサンプル グラフと、ドキュメント クラスによって指定されたデフォルトのテキストの幅と高さについては、両方のグループで を にscrreprt置き換えるだけで十分です。width=...height=0.21\textheightsubfig

ここに画像の説明を入力してください

テキストの幅、テキストの高さ、および隣り合って配置する必要がある画像のペアの比率の他の組み合わせについては、どの値がheight=...適切であるかを見つけるために少し実験する必要があるでしょう。

グラフのペアをできるだけ大きく、つまりテキストブロックの全幅に広げることが目的であると想定しています。この想定が正しい場合、指示は\centering必要ありません。

\documentclass{scrreprt}
\usepackage{subfig}
\usepackage{graphicx}
\begin{document}
\chapter{Figures}

\begin{figure}[h!]
\subfloat[Figure one]{%
\includegraphics[height=0.21\textheight]{example-image-a}}
\hspace*{\fill}
\subfloat[Figure two with different side proportions]{%
\includegraphics[height=0.21\textheight]{example-image-16x9}}
\caption{How to get the two figures to same height (respecting proportions)?}\end{figure}
\end{document}

答え2

高さのみを定義します。\includegraphics[height=33mm]{example-image-a}}(希望に応じて画像の高さを選択します)。

話題外:\centeringサブフロート内では使用しないでください...

編集:

あなたの場合、両方の画像に同じheightキーを使用したいのでGin、以下の編集したコードのように を使用します。画像をできるだけ離すには、\hfillの代わりにを使用しますquad

\documentclass{scrreprt}
\usepackage{subfig}
\usepackage{graphicx}

%---------------- show page layout. don't use in a real document!
\usepackage{showframe}
\renewcommand\ShowFrameLinethickness{0.15pt}
\renewcommand*\ShowFrameColor{\color{red}}
%---------------------------------------------------------------%
\begin{document}
    \chapter{Figures}
    \begin{figure}[h!]
    \setkeys{Gin}{height=44mm}
        \subfloat[Figure one]{\includegraphics{example-image-a}}
        \hfill% push sub images apart, so take all the line
        \subfloat[Figure two with different side proportions]{%
            \includegraphics{example-image-16x9}}
        \caption{How to get the two figures to same height (respecting proportions)?}
    \end{figure}
\end{document}

ここに画像の説明を入力してください

(赤い線はテキストの境界線を示します)

答え3

両方の画像を同じ高さにするには、最初の画像の高さを次元に保存します。次に、 を2 番目の画像に\imageheight使用します。height=\imageheight

ここでの問題は、両方の画像の幅をテキスト幅にできるだけ合うように自動的に定義できないことです。おそらく lua を使用したコードでそれができるのでしょうが、今まで私は TeX で lua を使用する方法を学んでいませんでした...

それで、半自動でやってみましょう...

コードを見てみましょう。プリアンブルの行で

\newdimen\imageheight

最初の画像の高さを格納するための新しい次元を宣言します\imageheight。コードでは

\settoheight{\imageheight}{% <==========================================
  \includegraphics[width=0.40\textwidth,keepaspectratio]{example-image-a}%
}

選択した幅に対する画像の現在の高さを取得しますwidth=0.40\textwidth

これでコードが使えるようになりました

\subfloat[Figure one]{%
  \centering\includegraphics[height=\imageheight]{example-image-a}}
\qquad
\subfloat[Figure two with different side proportions]{%
  \centering\includegraphics[height=\imageheight]{example-image-16x9}}

同じ高さで画像を印刷します。テキストの幅に合わせるには、最初の画像の幅を調整します: width=0.40\textwidth。 の値を0.40\textwidth必要に応じて変更します。

完全なコード

\documentclass{scrreprt}

\usepackage{subfig}
\usepackage{graphicx}
\usepackage{showframe}

\newdimen\imageheight % to store the actual image height <==============


\begin{document}

\settoheight{\imageheight}{% <==========================================
  \includegraphics[width=0.40\textwidth,keepaspectratio]{example-image-a}%
}

\chapter{Figures}
\begin{figure}[h!]
  \centering
    \subfloat[Figure one]{%
      \centering\includegraphics[height=\imageheight]{example-image-a}} % <=============
    \qquad
    \subfloat[Figure two with different side proportions]{%
      \centering\includegraphics[height=\imageheight]{example-image-16x9}} % <==========
  \caption{How to get the two figures to same height (respecting proportions)?}
\end{figure}
\end{document}

結果は次のようになります:

ここに画像の説明を入力してください

関連情報