![控制子图标题和子图位置](https://linux22.com/image/342175/%E6%8E%A7%E5%88%B6%E5%AD%90%E5%9B%BE%E6%A0%87%E9%A2%98%E5%92%8C%E5%AD%90%E5%9B%BE%E4%BD%8D%E7%BD%AE.png)
下面的代码
\documentclass{article}
\usepackage{graphicx, caption, subcaption}
\begin{document}
This article is about geometrical figures.
\begin{figure}[h]
\begin{subfigure}[b]{0.4\textwidth}
\includegraphics[width=\textwidth]{image1_example}
\caption{The rectangle is a complicated geometrical figure that has 4 edges and 4 vertices while a star is an even more complex geometrical figure}
\end{subfigure}
\begin{subfigure}[b]{0.4\textwidth}
\includegraphics[width=\textwidth]{image2_example}
\caption{A simple circle and a spiral}
\end{subfigure}
\caption{Geometrical figures}
\end{figure}
\end{document}
产生以下输出
子图 a) 的更详细标题导致两个子图的位置不对称。
如果两个子图之间有更多的水平空间,那就更好了。
是否可以控制这些功能?
答案1
环境的可选参数subfigure
提供了子标题的位置锚。这用于垂直对齐子标题。以下是视觉效果:
\documentclass{article}
\usepackage{graphicx,subcaption}
\begin{document}
\begin{figure}
\centering
\texttt{subfigure} with \texttt{[t]}op alignment
\medskip
\begin{subfigure}[t]{.3\linewidth}
\centering\includegraphics[width=.5\linewidth]{example-image-a}
\caption{This is a sub-caption. This is a sub-caption. This is a sub-caption}
\end{subfigure}
\begin{subfigure}[t]{.3\linewidth}
\centering\includegraphics[width=.5\linewidth]{example-image-b}
\caption{This is a sub-caption.}
\end{subfigure}
\begin{subfigure}[t]{.3\linewidth}
\centering\includegraphics[width=.5\linewidth]{example-image-c}
\caption{This is a sub-caption. This is a sub-caption.}
\end{subfigure}
\bigskip\hrulefill\bigskip
\texttt{subfigure} with \texttt{[c]}entre alignment (default)
\medskip
\begin{subfigure}{.3\linewidth}
\centering\includegraphics[width=.5\linewidth]{example-image-a}
\caption{This is a sub-caption. This is a sub-caption. This is a sub-caption}
\end{subfigure}
\begin{subfigure}{.3\linewidth}
\centering\includegraphics[width=.5\linewidth]{example-image-b}
\caption{This is a sub-caption.}
\end{subfigure}
\begin{subfigure}{.3\linewidth}
\centering\includegraphics[width=.5\linewidth]{example-image-c}
\caption{This is a sub-caption. This is a sub-caption.}
\end{subfigure}
\bigskip\hrulefill\bigskip
\texttt{subfigure} with \texttt{[b]}ottom alignment
\medskip
\begin{subfigure}[b]{.3\linewidth}
\centering\includegraphics[width=.5\linewidth]{example-image-a}
\caption{This is a sub-caption. This is a sub-caption. This is a sub-caption}
\end{subfigure}
\begin{subfigure}[b]{.3\linewidth}
\centering\includegraphics[width=.5\linewidth]{example-image-b}
\caption{This is a sub-caption.}
\end{subfigure}
\begin{subfigure}[b]{.3\linewidth}
\centering\includegraphics[width=.5\linewidth]{example-image-c}
\caption{This is a sub-caption. This is a sub-caption.}
\end{subfigure}
\end{figure}
\end{document}
因此我会使用[t]
op 对齐。此外,您还可以使用多种选项来展开这些数字。
\documentclass{article}
\usepackage{graphicx,subcaption}
\usepackage[margin=1cm,showframe]{geometry}% Just for this example
\begin{document}
\begin{figure}
\centering
Fixed separation using \verb|\quad| (or \verb|\qquad|, or \verb|\hspace|)
\medskip
\begin{subfigure}[t]{.4\linewidth}
\centering\includegraphics[width=.5\linewidth]{example-image-a}
\caption{This is a sub-caption. This is a sub-caption. This is a sub-caption}
\end{subfigure}\quad
\begin{subfigure}[t]{.4\linewidth}
\centering\includegraphics[width=.5\linewidth]{example-image-b}
\caption{This is a sub-caption.}
\end{subfigure}
\bigskip\hrulefill\bigskip
Even spread via \verb|\hfill|
\medskip
\mbox{}\hfill
\begin{subfigure}[t]{.4\linewidth}
\centering\includegraphics[width=.5\linewidth]{example-image-a}
\caption{This is a sub-caption. This is a sub-caption. This is a sub-caption}
\end{subfigure}\hfill
\begin{subfigure}[t]{.4\linewidth}
\centering\includegraphics[width=.5\linewidth]{example-image-b}
\caption{This is a sub-caption.}
\end{subfigure}
\hfill\mbox{}
\bigskip\hrulefill\bigskip
Full spread via \verb|\hfill|
\medskip
\begin{subfigure}[t]{.4\linewidth}
\centering\includegraphics[width=.5\linewidth]{example-image-a}
\caption{This is a sub-caption. This is a sub-caption. This is a sub-caption}
\end{subfigure}\hfill
\begin{subfigure}[t]{.4\linewidth}
\centering\includegraphics[width=.5\linewidth]{example-image-b}
\caption{This is a sub-caption.}
\end{subfigure}
\end{figure}
\end{document}
如果您的图片有不同的垂直高度,并且您也想对齐它们,则可以将内容提升到位;图像的默认对齐方式是在基线:
\documentclass{article}
\usepackage{graphicx,subcaption}
\newsavebox{\imagebox}
\begin{document}
\begin{figure}
\centering
Default
\medskip
\begin{subfigure}[t]{.4\linewidth}
\centering\includegraphics[width=.5\linewidth,height=75pt]{example-image-a}
\caption{This is a sub-caption. This is a sub-caption. This is a sub-caption}
\end{subfigure}\qquad
\begin{subfigure}[t]{.4\linewidth}
\centering\includegraphics[width=.5\linewidth,height=5pc]{example-image-b}
\caption{This is a sub-caption.}
\end{subfigure}
\bigskip\hrulefill\bigskip
\verb|\raisebox| to vertical top
\medskip
% Store largest image in a box
\savebox{\imagebox}{\includegraphics[width=.2\linewidth,height=75pt]{example-image-a}}%
\begin{subfigure}[t]{.4\linewidth}
\centering\usebox{\imagebox}% Place largest image
\caption{This is a sub-caption. This is a sub-caption. This is a sub-caption}
\end{subfigure}\qquad
\begin{subfigure}[t]{.4\linewidth}
\centering\raisebox{\dimexpr\ht\imagebox-\height}{% Raise smaller image into place
\includegraphics[width=.5\linewidth,height=5pc]{example-image-b}}%
\caption{This is a sub-caption.}
\end{subfigure}
\bigskip\hrulefill\bigskip
\verb|\raisebox| to vertical centre
\medskip
% Store largest image in a box
\savebox{\imagebox}{\includegraphics[width=.2\linewidth,height=75pt]{example-image-a}}%
\begin{subfigure}[t]{.4\linewidth}
\centering\usebox{\imagebox}% Place largest image
\caption{This is a sub-caption. This is a sub-caption. This is a sub-caption}
\end{subfigure}\qquad
\begin{subfigure}[t]{.4\linewidth}
\centering\raisebox{\dimexpr.5\ht\imagebox-.5\height}{% Raise smaller image into place
\includegraphics[width=.5\linewidth,height=5pc]{example-image-b}}%
\caption{This is a sub-caption.}
\end{subfigure}
\end{figure}
\end{document}
答案2
使用
subfigure
选项[t]
代替[b]
。要在图形之间添加一些水平空间,请在环境之间放置
\quad
、\qquad
或\hfill
一些\hspace
命令subfigure
。
。
\documentclass{article}
\usepackage{graphicx, caption, subcaption}
\begin{document}
This article is about geometrical figures.
\begin{figure}
\begin{subfigure}[t]{0.4\textwidth}
\includegraphics[width=\textwidth]{example-image-a}
\caption{The rectangle is a complicated geometrical figure that has 4 edges and 4 vertices while a star is an even more complex geometrical figure}
\end{subfigure}
\hfill
\begin{subfigure}[t]{0.35\textwidth}
\includegraphics[width=\textwidth]{example-image-b}
\caption{A simple circle and a spiral}
\end{subfigure}
\caption{Geometrical figures}
\end{figure}
\end{document}
答案3
使用包
\usepackage{graphicx}
\usepackage{caption}
\usepackage{subcaption}
\usepackage{subfigure}
\usepackage{subfloat}
\usepackage{float}
然后像这样编码:
\begin{figure*}[ht!]
\centering
\subfigure[]
{
\label{subfig:lab1}
\includegraphics[width=.3\textwidth]{figures/1.pdf} % .png .jpg ... according to supported graphics files
}
%
\subfigure[]
{
\label{subfig:lab2}
\includegraphics[width=.3\textwidth]{figures/2.pdf} % .png .jpg ... according to supported graphics files
}
%
\subfigure[]
{
\label{subfig:lab3}
\includegraphics[width=.3\textwidth]{figures/3.pdf} % .png .jpg ... according to supported graphics files
}\\ % for new row or line of subfigures
%
\subfigure[Caption 4]
{
\label{subfig:lab4}
\includegraphics[width=.3\textwidth]{figures/4.pdf} % .png .jpg ... according to supported graphics files
}
%
\subfigure[Caption 5]
{
\label{subfig:lab6}
\includegraphics[width=.3\textwidth]{figures/5.pdf} % .png .jpg ... according to supported graphics files
}
%
\subfigure[Caption 6]
{
\label{subfig:lab6}
\includegraphics[width=.3\textwidth]{figures/6.pdf} % .png .jpg ... according to supported graphics files
}
%
\caption{Figure Caption}
\label{fig:Figure ref}
\end{figure*}