我在使用 subfigure 包和正确对齐图形时遇到了麻烦。我对 Latex 不熟悉,所以请对明显的错误表示歉意。左上角的图形与下面的图形没有正确对齐。它应该更靠左(请参阅所附的屏幕截图)。缩短代码:
\begin{figure}[h]
hfill
\subfigure[CEO fixed / total]{\includegraphics[width=8cm]{figures/scatter_cash_CapIQ_CEOfixed_to_total.png}}
\hfill
\subfigure[CEO bonus / total]{\includegraphics[width=8cm{figures/scatter_cash_CapIQ_CEObonus_to_total.png}}
\hfill
\subfigure[CEO long-term / total]{\includegraphics[width=8cm]{figures/scatter_cash_CapIQ_CEOlongterm_to_total.png}}
\hfill
\caption{Compensation measures}
\end{figure}
答案1
尝试这个解决方案。
\documentclass{article}
\usepackage{graphicx}
\usepackage{caption}
\usepackage{subcaption}
\begin{document}
\begin{figure}[!h]
\centering
\begin{tabular}[c]{cc}
\begin{subfigure}[c]{0.4\textwidth}
\includegraphics[width=\textwidth]{figures/scatter_cash_CapIQ_CEOfixed_to_total.png}
\caption{CEO fixed / total}
\label{fig:ceoa}
\end{subfigure}&
\begin{subfigure}[c]{0.4\textwidth}
\includegraphics[width=\textwidth]{figures/scatter_cash_CapIQ_CEOfixed_to_total.png}
\caption{CEO fixed / total}
\label{fig:ceob}
\end{subfigure}\\
\begin{subfigure}[c]{0.4\textwidth}
\includegraphics[width=\textwidth]{figures/scatter_cash_CapIQ_CEOfixed_to_total.png}
\caption{CEO fixed / total}
\label{fig:ceoc}
\end{subfigure}&
\begin{subfigure}[c]{0.4\textwidth}
\includegraphics[width=\textwidth]{figures/scatter_cash_CapIQ_CEOfixed_to_total.png}
\caption{CEO fixed / total}
\label{fig:ceod}
\end{subfigure}\\
\end{tabular}
\caption{Compensation measures}
\label{fig:ceo}
\end{figure}
\end{document}
怎么运行的?
- 您可以使用表格环境来控制子图的定位。每个图都位于表格中的一个单元格中。列居中。因此,即使您更改图的大小,图仍保持水平对齐。
- 每个子图都有
[c]
位置说明符。因此,图形仍然垂直排列在一行中。 - 如果您需要更改图形大小,请更改乘数
\textwidth
(本例中为 0.4。因此,两个并排的图形占用文本宽度的 0.4 X 2 = 0.8,留出足够的空白)。但不要将它们弄得太大,否则框会过满。
答案2
单独使用subcaption
。如果我们可以在水平方向\hspace{}
上在两个相邻的subfigure
环境之间使用,那么我们必须被允许在垂直方向vspace{}
上在两个相邻的subfigure
环境之间使用。我不知道这种理念是否正确。但它似乎是正确的,不是吗?
在下面的例子中,我故意为每张图片选择了不同的尺寸,只是为了通用性。但你可以根据自己的喜好进行更改。
\documentclass[preview,border=12pt]{standalone}
\usepackage[demo]{graphicx}
\usepackage{subcaption}
\begin{document}
Beauty without intelligence is a masterpiece painted on a toilet paper.
\begin{figure}[hbtp]
\centering
\begin{subfigure}[c]{.4\linewidth}
\centering
\includegraphics[width=4cm]{foo}
\caption{foo}
\label{fig:foo}
\end{subfigure}\hspace{12pt}
\begin{subfigure}[c]{.4\linewidth}
\centering
\includegraphics[width=3cm]{goo}
\caption{goo}
\label{fig:goo}
\end{subfigure}\vspace{12pt}
\begin{subfigure}[c]{.4\linewidth}
\centering
\includegraphics[height=4cm]{hoo}
\caption{hoo}
\label{fig:hoo}
\end{subfigure}\hspace{24pt}
\begin{subfigure}[c]{.4\linewidth}
\centering
\includegraphics[height=3cm]{ioo}
\caption{ioo}
\label{fig:ioo}
\end{subfigure}
\caption{The group of foo, goo, hoo, and ioo.}
\label{fig:group}
\end{figure}
\end{document}
同质情况
当所有图像具有相同的尺寸时,输出看起来会好得多,如下所示。
\documentclass[preview,border=12pt]{standalone}
\usepackage[demo]{graphicx}
\usepackage{array}
\usepackage{subcaption}
\begin{document}
Beauty without intelligence is a masterpiece painted on a toilet paper.
\begin{figure}[hbtp]
\centering
\begin{subfigure}[c]{.4\linewidth}
\centering
\includegraphics[width=4cm]{foo}
\caption{foo}
\label{fig:foo}
\end{subfigure}\hspace{12pt}
\begin{subfigure}[c]{.4\linewidth}
\centering
\includegraphics[width=4cm]{goo}
\caption{goo}
\label{fig:goo}
\end{subfigure}\vspace{12pt}
\begin{subfigure}[c]{.4\linewidth}
\centering
\includegraphics[width=4cm]{hoo}
\caption{hoo}
\label{fig:hoo}
\end{subfigure}\hspace{12pt}
\begin{subfigure}[c]{.4\linewidth}
\centering
\includegraphics[width=4cm]{ioo}
\caption{ioo}
\label{fig:ioo}
\end{subfigure}
\caption{The group of foo, goo, hoo, and ioo.}
\label{fig:group}
\end{figure}
\end{document}
答案3
试试这个:(只需将 image.png 替换为所需的图像文件)
\documentclass{article}
\usepackage[tight]{subfigure}
% If you want to control the alignment of the pictures
% more accurately, uncomment these and try different values
% \subfigcapmargin = .5cm
% \subfigtopskip = 2cm
% \subfigcapskip = 2cm
% \subfigcaptopadj = 1cm
% \subfigbottomskip = 2cm
% \subfiglabelskip = 2cm
\usepackage{graphicx}
\begin{document}
\begin{figure}%
\centering
\subfigure[][]{%
\label{fig:ex3-a}%
\includegraphics[width=0.45\textwidth]{image.png}}%
\hspace{8pt}%
\subfigure[][]{%
\label{fig:ex3-b}%
\includegraphics[width=0.45\textwidth]{image.png}}\\
\subfigure[][]{%
\label{fig:ex3-c}%
\includegraphics[width=0.45\textwidth]{image.png}}%
\hspace{8pt}%
\subfigure[][]{%
\label{fig:ex3-d}%
\includegraphics[width=0.45\textwidth]{image.png}}%
\caption[A set of four subfigures.]{A set of four subfigure
s:
\subref{fig:ex3-a} describes the first subfigure;
\subref{fig:ex3-b} describes the second subfigure;
\subref{fig:ex3-c} describes the third subfigure; and,
\subref{fig:ex3-d} describes the last subfigure.}%
\label{fig:ex3}%
\end{figure}
\end{document}
摘自子图包文档
答案4
使用minipage
-s 可能比手动间距或使用表格更好。
\documentclass{article}
\usepackage[demo]{graphicx}
\usepackage{caption}
\usepackage{subcaption}
\begin{document}
\begin{figure}[!h]
\centering
\begin{subfigure}[c]{0.65\textwidth}
\includegraphics[width=\textwidth]{figures/scatter_cash_CapIQ_CEOfixed_to_total.png}
\caption{CEO fixed / total}
\label{fig:ceoa}
\end{subfigure}\hfill%
\begin{subfigure}[c]{0.25\textwidth}
\includegraphics[width=\textwidth]{figures/scatter_cash_CapIQ_CEOfixed_to_total.png}
\caption{CEO fixed / total}
\label{fig:ceob}
\end{subfigure}
\begin{subfigure}[c]{0.65\textwidth}
\includegraphics[width=\textwidth]{figures/scatter_cash_CapIQ_CEOfixed_to_total.png}
\caption{CEO fixed / total}
\label{fig:ceoc}
\end{subfigure}\hfill%
\begin{subfigure}[c]{0.25\textwidth}
\includegraphics[width=\textwidth]{figures/scatter_cash_CapIQ_CEOfixed_to_total.png}
\caption{CEO fixed / total}
\label{fig:ceod}
\end{subfigure}
\caption{Compensation measures}
\label{fig:ceo}
\end{figure}
\end{document}