我试图将两个具有不同高度的子图置于中心,但似乎无法将它们对齐。
原代码是这样的,子图底部对齐
\begin{figure}
\subfloat[Users collection.]{\includegraphics[width=0.4\textwidth]{Images/Database_users.png}\label{fig:database:subfig1}}%
\qquad
\subfloat[Events collection.]{\includegraphics[width=0.4\textwidth]{Images/Database_events.png}\label{fig:database:subfig2}}%
\centering
\caption{Database Architecture}
\label{fig:database}
\end{figure}
我尝试了包文档中的建议,但右侧标题对齐到右侧,并且图形溢出到文档的其余部分并与文本重叠:
\newsavebox{\tempbox}
\begin{figure}
\sbox{\tempbox}{\includegraphics[width=0.4\textwidth]{Images/Database_users.png}}
\subfloat[Users collection.]{\usebox{\tempbox}\label{fig:database:subfig1}}%
\qquad
\subfloat[Events collection]{\vbox to \ht\tempbox{%
\vfil
\includegraphics[width=0.4\textwidth]{Images/Database_events.png}
\vfil}\label{fig:database:subfig2}}%
\caption{database}\label{fig:database}
\end{figure}
我也尝试使用 \raisebox 但凸起的图形从文档中消失了:
\begin{figure}
\subfloat[Users collection.]{\raisebox{0.5em}\includegraphics[width=0.4\textwidth]{Images/Database_users.png}\label{fig:database:subfig1}}%
\qquad
\subfloat[Events collection.]{\includegraphics[width=0.4\textwidth]{Images/Database_events.png}\label{fig:database:subfig2}}%
\centering
\caption{Database Architecture}
\label{fig:database}
\end{figure}
任何帮助都值得感激。提前致谢
答案1
应用将使\raisebox{-.5\height}{}
图形围绕基线居中。
\documentclass{article}
\usepackage{graphicx,subfig}
\begin{document}
\begin{figure}
\subfloat[Users collection.]{\raisebox{-.5\height}{%
\includegraphics[height=30pt,width=0.4\textwidth]{example-image-a}}%
\label{fig:database:subfig1}}%
\qquad
\subfloat[Events collection.]{\raisebox{-.5\height}{%
\includegraphics[height=50pt,width=0.4\textwidth]{example-image-b}}%
\label{fig:database:subfig2}}%
\centering
\caption{Database Architecture}
\label{fig:database}
\end{figure}
\end{document}
如果您还需要对齐标题,则将\rule
最高图像的高度添加到其他图形中。
\documentclass{article}
\usepackage{graphicx,subfig}
\begin{document}
\begin{figure}
\subfloat[Users collection.]{\raisebox{-.5\height}{%
\includegraphics[height=30pt,width=0.4\textwidth]{example-image-a}}%
\label{fig:database:subfig1}\rule[-25pt]{0pt}{50pt}}%
\qquad
\subfloat[Events collection.]{\raisebox{-.5\height}{%
\includegraphics[height=50pt,width=0.4\textwidth]{example-image-b}}%
\label{fig:database:subfig2}}%
\centering
\caption{Database Architecture}
\label{fig:database}
\end{figure}
\end{document}
答案2
使用subcaption
包很容易:
\documentclass{article}
\usepackage{graphicx}
\usepackage{subcaption}
\begin{document}
\begin{figure}
\begin{minipage}[c]{.5\linewidth}
\centering
\includegraphics[width=2cm,height=1cm]{example-image}
\subcaption{A subfigure}\label{fig:1a}
\end{minipage}%
\begin{minipage}[c]{.5\linewidth}
\centering
\includegraphics[width=2cm,height=2cm]{example-image}
\subcaption{Another subfigure}\label{fig:1b}
\end{minipage}
\caption{A figure}\label{fig:1}
\end{figure}
\end{document}