我想将两张不同大小的图片并排放置。两张图像都应有单独的subcaption
。一切正常。我唯一的问题是:如何让较小的图像相对于较大的图像垂直居中?
\documentclass[a4paper,10pt]{scrreprt}
\usepackage[T1]{fontenc}
% \usepackage[utf8]{inputenc}
\usepackage[latin1]{inputenc}
\usepackage{geometry}
\geometry{a4paper,left=25mm,right=25mm, top=25mm, bottom=25mm}
\usepackage{subcaption}
\usepackage{tikz}
\begin{document}
\begin{figure}[htbp]
\centering
\hfill
\begin{subfigure}[b]{0.48\textwidth}
\centering
\includegraphics[height=.22\textheight]{example-image-a}
\caption{Subcaption left}
\end{subfigure}
\hfill
\begin{subfigure}[b]{0.48\textwidth}
\centering
\includegraphics[height=.18\textheight]{example-image-b}
\caption{Subcaption right}
\end{subfigure}
\hfill
\caption{Caption}
\end{figure}
\end{document}
答案1
您可以按照在子字幕垂直对齐和figure*
在环境中垂直对齐不同尺寸的图像即,捕获较大图像的尺寸,并利用其高度来调整较小图像的垂直位置。
\documentclass{article}
\usepackage{geometry,graphicx}
\geometry{a4paper,margin=1in}
\usepackage{subcaption}
\newsavebox{\largestimage}
\begin{document}
\begin{figure}[htbp]
\centering
% Store largest image in a box
\savebox{\largestimage}{\includegraphics[height=.22\textheight]{example-image-a}}%
\begin{subfigure}[b]{0.48\textwidth}
\centering
\usebox{\largestimage}
\caption{Subcaption left}
\end{subfigure}
\quad
\begin{subfigure}[b]{0.48\textwidth}
\centering
% Adjust vertical height of smaller image
\raisebox{\dimexpr.5\ht\largestimage-.5\height}{%
\includegraphics[height=.18\textheight]{example-image-b}}
\caption{Subcaption right}
\end{subfigure}
\caption{Caption}
\end{figure}
\end{document}
垂直调整为较大图像高度的 50%减较小图像高度的 50%。从技术上讲,这给出了较小图像周围 50% 的垂直空白……相对于较大图像垂直居中。