我有 4 张图片,我希望它们都沿着垂直和水平边缘对齐。问题是右上图片上的标题占了 2 行,而左上图片上的标题只占 1 行,导致它们错位。它看起来像这样
我怎样才能强制它们对齐?我正在使用以下包和模板:
\documentclass[annual]{acmsiggraph}
\usepackage{graphicx}
\usepackage{caption}
\usepackage{subcaption}
\begin{document}
\begin{figure}[htbp]
\centering
\begin{subfigure}[b]{0.2\textwidth}
\includegraphics[width=\textwidth]{images/donald}
\caption{Original image.}
\label{fig:pearl-original}
\end{subfigure}
~ %add desired spacing between images, e. g. ~, \quad, \qquad, \hfill etc.
%(or a blank line to force the subfigure onto a new line)
\begin{subfigure}[b]{0.2\textwidth}
\includegraphics[width=\textwidth]{images/donald_gray}
\caption{The image after blurring and extracting the luminance channel.}
\label{fig:pearl-human}
\end{subfigure}
~ %add desired spacing between images, e. g. ~, \quad, \qquad, \hfill etc.
%(or a blank line to force the subfigure onto a new line)
\begin{subfigure}[b]{0.2\textwidth}
\includegraphics[width=\textwidth]{images/donald_sobel_x.png}
\caption{The image after applying a vertical sobel filter.}
\label{fig:pearl-paint}
\end{subfigure}
~ %add desired spacing between images, e. g. ~, \quad, \qquad, \hfill etc.
%(or a blank line to force the subfigure onto a new line)
\begin{subfigure}[b]{0.2\textwidth}
\includegraphics[width=\textwidth]{images/donald_sobel_y.png}
\caption{The image after applying a horizonal sobel filter}
\label{fig:pearl-paint}
\end{subfigure}
\caption{Different stages of the image processing pipeline.}
\label{fig:pipeline}
\end{figure}
\end{document}
答案1
您可以使用\begin{subfigure}[t]{0.4\linewidth}
,即 [t] 而不是 [b]。
我尝试使用以下包和模板:
\documentclass{article}
\usepackage{caption}
\usepackage{graphicx}
\usepackage{subcaption}
\captionsetup{compatibility=false}
\begin{document}
\begin{figure}[h!t!b]
\centering
\begin{subfigure}[t]{0.4\linewidth} \includegraphics[width=\linewidth]{"image".png}
\caption{image1}
\end{subfigure}
\begin{subfigure}[t]{0.4\linewidth}
\includegraphics[width=\linewidth]{"image".png}
\caption{image2 has a very long caption to be fit}
\end{subfigure}\\
\begin{subfigure}[t]{0.4\linewidth}
\includegraphics[width=\linewidth]{"image".png}
\caption{image3}
\end{subfigure}
\begin{subfigure}[t]{0.4\linewidth}
\includegraphics[width=\linewidth]{"image".png}
\caption{image4}
\end{subfigure}
\caption{Different Images}
\label{Images}
\end{figure}
\end{document}
答案2
如果图像高度相同且标题长度不同,则对齐图像顶部是合理的:
\documentclass{article} % i haven't your document style,
% however a proposed solution work witha anyone
\usepackage[demo]{graphicx}
\usepackage{caption}
\usepackage{subcaption}
%-------------------------------------- only for show page layout
\usepackage{showframe}
\renewcommand\ShowFrameLinethickness{0.25pt}
\renewcommand*\ShowFrameColor{\color{red}}
%---------------------------------------------------------------%
\usepackage{lipsum}
\begin{document}
begin{figure}[htbp]
\centering
% images in the first row
\begin{subfigure}[t]{0.2\linewidth}
\includegraphics[width=\linewidth]{images/donald}
\caption{Original image.}
\label{fig:pearl-original}
\end{subfigure}
~
\begin{subfigure}[t]{0.2\linewidth}
\includegraphics[width=\linewidth]{images/donald_gray}
\caption{The image after blurring and extracting the luminance channel.}
\label{fig:pearl-human}
\end{subfigure}
% images in the second row
\begin{subfigure}[t]{0.2\linewidth}
\includegraphics[width=\linewidth]{images/donald_sobel_x.png}
\caption{The image after applying a vertical sobel filter.}
\label{fig:pearl-paint}
\end{subfigure}
~
\begin{subfigure}[t]{0.2\linewidth}
\includegraphics[width=\linewidth]{images/donald_sobel_y.png}
\caption{The image after applying a horizonal sobel filter}
\label{fig:pearl-paint}
\end{subfigure}
\caption{Different stages of the image processing pipeline.}
\label{fig:pipeline}
\end{figure}
\end{document}
(红线表示页面布局)
编辑:我不小心上传了两个不同的代码。另外,我错过了你喜欢将图像放在两行(这从你的代码中看不出来。现在已更正。
如果你的文档有两列,那么宽度为subfigure
s 的选择
\begin{subfigure}[t]{0.4\linewidth}
或者
\begin{subfigure}[t]{0.4\columnwidth}