LaTeX에서 하위 그림의 높이가 동일하고 선폭의 전체 X%를 차지하도록 강제

LaTeX에서 하위 그림의 높이가 동일하고 선폭의 전체 X%를 차지하도록 강제

크기가 다른 두 개의 이미지로 구성된 도형을 만들고 싶습니다. 나는 그것들이 같은 높이를 갖고 전체적으로 선 너비의 90%를 차지하도록 나란히 배치하고 싶습니다.

동일한 고정 높이(예: cm)를 갖도록 만드는 것은 쉽지만, 원하는 전체 너비를 충족하도록 이 공통 높이를 자동으로 조정하는 방법은 무엇입니까? 수동 시행착오는 시간이 많이 걸리고 대략적이며 견고하지 않습니다.

다른 LaTeX 패키지가 있든 없든 솔루션은 subfigure괜찮습니다.

답변1

동일한(다소 임의의) 높이로 포함시킨 다음 원하는 너비로 함께 크기를 조정할 수 있습니다.

여기에 이미지 설명을 입력하세요

\documentclass{article}

\usepackage{graphicx}% images from mwe package

\begin{document}

\noindent X\dotfill X

\begin{center}
\resizebox{.9\textwidth}{!}{%
\includegraphics[height=3cm]{example-image-a}%
\quad
\includegraphics[height=3cm]{example-image-16x9}%
}
\end{center}

\end{document}

답변2

David가 제안한 대로 패키지를 사용 subcaption하고 계산을 수행할 수 있습니다.

\documentclass{article}

\usepackage{graphicx}% images from mwe package
\usepackage{subcaption}

\newlength{\twosubht}
\newsavebox{\twosubbox}

\begin{document}

\noindent\hrulefill The text width\hrulefill

\begin{center}
\makebox[.9\textwidth]{\hrulefill 90\% of text width\hrulefill}
\end{center}

\begin{figure}[htp]

% preliminary
\sbox\twosubbox{%
  \resizebox{\dimexpr.9\textwidth-1em}{!}{%
    \includegraphics[height=3cm]{example-image-a}%
    \includegraphics[height=3cm]{example-image-16x9}%
  }%
}
\setlength{\twosubht}{\ht\twosubbox}

% typeset

\centering

\subcaptionbox{First\label{f}}{%
  \includegraphics[height=\twosubht]{example-image-a}%
}\quad
\subcaptionbox{Second\label{s}}{%
  \includegraphics[height=\twosubht]{example-image-16x9}%
}

\caption{The caption}

\end{figure}

\end{document}

여기에 이미지 설명을 입력하세요

답변3

\documentclass[a4paper,12pt]{article}
\usepackage{graphicx}
\usepackage{adjustbox}
\usepackage{fp}
\usepackage{subcaption}

\newlength{\totalimgwidth}
\newlength{\imgspacingwidth}

\newlength{\firstimgorigwidth}
\newlength{\firstimgorigheight}
\newlength{\secondimgorigwidth}
\newlength{\secondimgorigheight}
\newlength{\firstimgwidth}
\newlength{\secondimgwidth}

\newcommand{\setsubfloatwidths}[2]{%set the total width you want the images take and the spacing between them
\setlength{\totalimgwidth}{#1}%
\setlength{\imgspacingwidth}{#2}%
\addtolength{\totalimgwidth}{-\imgspacingwidth}%
}


\begin{document}
\setsubfloatwidths{0.9\textwidth}{1ex} %set the total width of figure and spacing inbetween
\begin{figure}
\adjincludegraphics[gstore width=\firstimgorigwidth,gstore height=\firstimgorigheight,gobble]{img1}%
\adjincludegraphics[gstore width=\secondimgorigwidth,gstore height=\secondimgorigheight,gobble]{img2}%
\makeatletter%
\FPdiv\firstaspectratio{\strip@pt\firstimgorigheight}{\strip@pt\firstimgorigwidth}%
\FPdiv\secondaspectratio{\strip@pt\secondimgorigheight}{\strip@pt\secondimgorigwidth}%
\FPeval\firstfactor{\secondaspectratio / (\firstaspectratio + \secondaspectratio)}%
\FPeval\secondfactor{\firstaspectratio / (\firstaspectratio + \secondaspectratio)}%
\makeatother%
\begin{subfigure}{\firstfactor\totalimgwidth}
\includegraphics[width=\textwidth]{img1}
\end{subfigure}
\hspace*{\imgspacingwidth}
\begin{subfigure}{\secondfactor\totalimgwidth}
\includegraphics[width=\textwidth]{img2}
\end{subfigure}
\end{figure}
\end{document}

를 사용하여 이미지가 원하는 전체 너비와 이미지 사이의 간격을 설정한 다음 두 이미지 파일을 인수로 사용하여 환경 내부를 \setsubfloatswidths호출하고 마지막으로 평소와 같이 하위 그림을 사용합니다.\adjincludegraphicsfigure

\firstfactor\secondfactor첫 번째 이미지의 크기를 조정하고 두 번째 이미지에 대해서도 동일한 작업을 수행하는 요소를 포함합니다 .

더 간단한 해결책은 이미지의 높이를 설정하는 것이었지만 \subcaptionsubfigure환경은 인수로 사용됩니다.넓이서브 플로트의.

관련 정보