我正在使用tabular
环境minipage
将 4 个图形以 2 x 2 布局对齐。虽然这四个图形大小相同,但子标题的长度不同,这导致图形错位。有什么方法可以纠正这个问题吗?
以下是我正在使用的代码:
\documentclass[compress]{beamer}
\usetheme{Warsaw}
\usepackage{setspace}
\usepackage[hang,footnotesize]{caption}
\usepackage[subrefformat=parens]{subcaption}
\captionsetup{compatibility=false}
\setbeamercolor{page number in head/foot}{fg=white}
\setbeamerfont{page number in head/foot}{size=\tiny}
\setbeamertemplate{page number in head/foot}[totalframenumber]
\title[]{Beamer title}
\author[]{Author name}
\begin{document}
\begin{frame}{Frame Title}
\begin{figure}
\begin{tabular}{cc}
% Figure 1
\begin{minipage}{0.45\hsize}
\centering
\includegraphics[keepaspectratio, scale=0.3]{sample.jpg}
\subcaption{Subcaption}
\end{minipage}
% Figure 2
\begin{minipage}{0.45\linewidth}
\centering
\includegraphics[keepaspectratio, scale=0.3]{sample.jpg}
\subcaption{Longer longer longer longer longer longer longer subcaption}
\end{minipage}
\\
% Figure 3
\begin{minipage}{0.45\hsize}
\centering
\includegraphics[keepaspectratio, scale=0.3]{sample.jpg}
\subcaption{Longer longer longer longer longer longer longer subcaption}
\end{minipage}
% Figure 4
\begin{minipage}{0.45\hsize}
\centering
\includegraphics[keepaspectratio, scale=0.3]{sample.jpg}
\subcaption{Subcaption}
\end{minipage}
\end{tabular}
\end{figure}
\end{frame}
\end{document}
答案1
您可以使用\begin{minipage}[t]
它们顶部对齐(或者更简单地删除minipage
并使用p{.45\textwidth}
列而不是c
答案2
使用\subcaptionbox
(手册第 2 部分subcaption
)。
该
\subcaptionbox
命令排版给定的内容和标题。它会自动根据第一行标题对齐子图和子表。
\documentclass[compress]{beamer}
\usetheme{Warsaw}
\usepackage{setspace}
\usepackage[hang,footnotesize]{caption}
\usepackage[subrefformat=parens]{subcaption}
\captionsetup{compatibility=false}
\setbeamercolor{page number in head/foot}{fg=white}
\setbeamerfont{page number in head/foot}{size=\tiny}
\setbeamertemplate{page number in head/foot}[totalframenumber]
\title[]{Beamer title}
\author[]{Author name}
\begin{document}
\begin{frame}{Frame Title}
\begin{figure}
\begin{tabular}{@{}cc@{}}
% Figure 1
\subcaptionbox{Subcaption}[0.45\textwidth][c]{%
\includegraphics[width=0.6\linewidth]{example-image}%
} &
% Figure 2
\subcaptionbox{%
Longer longer longer longer longer longer longer subcaption%
}[0.45\textwidth][c]{%
\includegraphics[width=0.6\linewidth]{example-image}%
} \\
% Figure 3
\subcaptionbox{%
Longer longer longer longer longer longer longer subcaption%
}[0.45\textwidth][c]{%
\includegraphics[width=0.6\linewidth]{example-image}%
} &
% Figure 4
\subcaptionbox{Subcaption}[0.45\textwidth][c]{%
\includegraphics[width=0.6\linewidth]{example-image}%
}
\end{tabular}
\end{figure}
\end{frame}
\end{document}