但对于垂直对齐的子图,为了节省一些垂直空间(我无法将尺寸缩小到比这更多)
我正在使用\subfig
包来对齐我的子图。这是我的代码:
\begin{figure}[ht!]
\centering
\begin{minipage}{\textwidth}
\centering
\subfloat[]
{
\includegraphics[width=0.6\textwidth, keepaspectratio]{fig_a}
\label{fig:a}
}
\\
\centering
\subfloat[]
{
\includegraphics[width=0.6\textwidth, keepaspectratio]{fig_b}
\label{fig:b}
}
\\
\centering
\subfloat[]
{
\includegraphics[width=0.6\textwidth, keepaspectratio]{fig_c}
\label{fig:c}
}
\caption{Three figures, take too much vertical space}
\label{fig:unified}
\end{minipage}
\end{figure}
答案1
请注意,只有图像位于中心,而不是标题。
理想情况下,应该将 放在\label
之后\caption
,但在这种情况下这是不可能的。相反,应该将 放在\label
标题内。否则,所使用的某些本地宏\label
可能会丢失。
\documentclass{article}
\usepackage{graphicx}
\usepackage{subcaption}
\captionsetup[sub]{justification=raggedright,singlelinecheck=false}
\usepackage{showframe}% debuggingh tool
\makeatletter
\newcommand{\mysub}[2][]% #1=caption (optional), #2=graphics
{\bgroup
\sbox0{#2}\usebox0
\dimen0=\dimexpr \textwidth-\wd0\relax
\ifx\\\@centercr \divide\dimen0 by 2\fi
\sbox1{\begin{minipage}[t]{\dimen0}
\subcaption{#1}%
\end{minipage}}%
\rlap{\raisebox{\dimexpr \ht0-\ht1}[0pt][0pt]{\usebox1}}\allowbreak
\egroup}
\makeatother
\begin{document}
\begin{figure}[p]
\centering
\mysub[A very long caption, just to test the limits. \label{fig:a}]
{\includegraphics[width=0.6\textwidth, keepaspectratio]{example-image-a}}
\mysub[\label{fig:b}]
{\includegraphics[width=0.6\textwidth, keepaspectratio]{example-image-b}}
\mysub[\label{fig:c}]
{\includegraphics[width=0.6\textwidth, keepaspectratio]{example-image-c}}
\caption{Three figures, take too much vertical space}
\label{fig:unified}
\end{figure}
\end{document}