请问如何使用包使以下数组水平居中对齐subfig
?
\documentclass[11pt]{article}
\usepackage[dvips]{graphicx}
\usepackage{subfig}
\begin{document}
\begin{figure}[htp]
\centering
\subfloat[From $n=0$ to $n=-1$]{\label{fig:a}
\includegraphics[scale=0.45]{Figures/IncludePyramid_a_reverse.eps}
}
\qquad\qquad\qquad
\subfloat[From $n=-1$ to $n=0$]{\label{fig:aa}
\includegraphics[scale=0.45]{Figures/IncludePyramid_a.eps}
} \\
\subfloat[From $n=-1$ to $n=-2$]{\label{fig:b}
\includegraphics[scale=0.45]{Figures/IncludePyramid_b_reverse.eps}
}
\qquad\qquad\qquad
\subfloat[From $n=-2$ to $n=-1$]{\label{fig:bb}
\includegraphics[scale=0.45]{Figures/IncludePyramid_b.eps}
}
\\
\subfloat[From $n=-2$ to $n=-3$]{\label{fig:c}
\includegraphics[scale=0.45]{Figures/IncludePyramid_c_reverse.eps}
}
\qquad\qquad\qquad
\subfloat[From $n=-3$ to $n=-2$]{\label{fig:cc}
\includegraphics[scale=0.45]{Figures/IncludePyramid_c.eps}
}
\caption{Random walk on the Pascal pyramid}
\label{fig:bratelli}
\end{figure}
\end{document}
答案1
你必须再努力一点。下面的一组宏将每个子浮点数设置在零宽度框中,因此添加填充空间即可。
该
\csubfloat
宏具有与;相同的语法,\subfloat
但请注意,图像不应填满整行。该
\centerhfill
宏有一个可选参数,默认\quad
在中间添加一个空格。如果还不够,你可以尝试一下\centerhfill[\qquad]
。
在示例中,我使用了demo
选项graphicx
;不要自己使用它,但dvips
也不要添加。
该\fakeig
宏仅用于生成测试,您不需要它;只需删除行并取消注释即可\includegraphics
。
\documentclass[11pt]{article}
\usepackage[demo]{graphicx}
\usepackage{subfig}
\newcommand{\csubfloat}[2][]{%
\makebox[0pt]{\subfloat[#1]{#2}}%
}
\newcommand{\centerhfill}[1][\quad]{\hspace{\stretch{0.5}}#1\hspace{\stretch{0.5}}}
% This is for the example
\newcommand{\fakeig}[2]{\includegraphics[width=#1,height=#2]{foo}}
\begin{document}
\begin{figure}[htp]
\centering
\hspace*{\fill}%
\csubfloat[From $n=0$ to $n=-1$]{\label{fig:a}%
% \includegraphics[scale=0.45]{Figures/IncludePyramid_a_reverse.eps}%
\fakeig{2cm}{2cm}%
}\centerhfill
\csubfloat[From $n=-1$ to $n=0$]{\label{fig:aa}%
% \includegraphics[scale=0.45]{Figures/IncludePyramid_a.eps}%
\fakeig{2cm}{2cm}%
}\hspace*{\fill}
\hspace*{\fill}%
\csubfloat[From $n=-1$ to $n=-2$]{\label{fig:b}%
% \includegraphics[scale=0.45]{Figures/IncludePyramid_b_reverse.eps}%
\fakeig{3cm}{3cm}%
}\centerhfill
\csubfloat[From $n=-2$ to $n=-1$]{\label{fig:bb}%
% \includegraphics[scale=0.45]{Figures/IncludePyramid_b.eps}%
\fakeig{3cm}{3cm}%
}\hspace*{\fill}
\hspace*{\fill}%
\csubfloat[From $n=-2$ to $n=-3$]{\label{fig:c}%
% \includegraphics[scale=0.45]{Figures/IncludePyramid_c_reverse.eps}%
\fakeig{4cm}{4cm}%
}\centerhfill
\csubfloat[From $n=-3$ to $n=-2$]{\label{fig:cc}%
% \includegraphics[scale=0.45]{Figures/IncludePyramid_c.eps}%
\fakeig{4cm}{4cm}%
}\hspace*{\fill}
\caption{Random walk on the Pascal pyramid}
\label{fig:bratelli}
\end{figure}
\end{document}
请注意,大量使用 来%
掩盖像空格一样的行尾,这是不需要的。
另一种选择是将每个都包含\subfloat
在minipage
宽度为 的一半的中\textwidth
,但您对中心间距的控制较少;这可以使用 的一小部分 进行修改\textwidth
,例如\begin{minipage}{.8\textwidth}
或类似。
\documentclass[11pt]{article}
\usepackage[demo]{graphicx}
\usepackage{subfig}
% This is for the example
\newcommand{\fakeig}[2]{\includegraphics[width=#1,height=#2]{foo}}
\begin{document}
\begin{figure}[htp]
\centering
\begin{minipage}{.5\textwidth}\centering
\subfloat[From $n=0$ to $n=-1$]{\label{fig:a}%
% \includegraphics[scale=0.45]{Figures/IncludePyramid_a_reverse.eps}%
\fakeig{2cm}{2cm}%
}
\end{minipage}%
\begin{minipage}{.5\textwidth}\centering
\subfloat[From $n=-1$ to $n=0$]{\label{fig:aa}%
% \includegraphics[scale=0.45]{Figures/IncludePyramid_a.eps}%
\fakeig{2cm}{2cm}%
}
\end{minipage}
\begin{minipage}{.5\textwidth}\centering
\subfloat[From $n=-1$ to $n=-2$]{\label{fig:b}%
% \includegraphics[scale=0.45]{Figures/IncludePyramid_b_reverse.eps}%
\fakeig{3cm}{3cm}%
}
\end{minipage}%
\begin{minipage}{.5\textwidth}\centering
\subfloat[From $n=-2$ to $n=-1$]{\label{fig:bb}%
% \includegraphics[scale=0.45]{Figures/IncludePyramid_b.eps}%
\fakeig{3cm}{3cm}%
}
\end{minipage}
\hspace*{\fill}%
\begin{minipage}{.5\textwidth}\centering
\subfloat[From $n=-2$ to $n=-3$]{\label{fig:c}%
% \includegraphics[scale=0.45]{Figures/IncludePyramid_c_reverse.eps}%
\fakeig{4cm}{4cm}%
}
\end{minipage}%
\begin{minipage}{.5\textwidth}\centering
\subfloat[From $n=-3$ to $n=-2$]{\label{fig:cc}%
% \includegraphics[scale=0.45]{Figures/IncludePyramid_c.eps}%
\fakeig{4cm}{4cm}%
}
\end{minipage}
\caption{Random walk on the Pascal pyramid}
\label{fig:bratelli}
\end{figure}
\end{document}
答案2
您可能不想使用subfig
包及其\subfloat macro
,而是希望使用subcaption
包及其subfigure
环境。具体来说,您可以指定subfigure
给定固定宽度的六个环境,例如,0.4\textwidth
并\centering
在每个环境中使用说明。
如果无法访问您的图像文件,则无法保证以下代码无需进一步调整即可正常工作。特别是,您可能需要更改环境的宽度subfigure
以容纳第三行子图中的图形。
\documentclass[11pt]{article}
\usepackage[demo]{graphicx} % omit 'demo' option in real document
\usepackage{subcaption} % for 'subfigure' environment
\begin{document}
\begin{figure}
\centering
\begin{subfigure}{0.4\textwidth}
\centering
\includegraphics[scale=0.45]{Figures/IncludePyramid_a_reverse.eps}
\caption{From $n=0$ to $n=-1$}\label{fig:a}
\end{subfigure}
\qquad\qquad\qquad % spacing between the subfigures
\begin{subfigure}{0.4\textwidth}
\centering
\includegraphics[scale=0.45]{Figures/IncludePyramid_a.eps}
\caption{From $n=-1$ to $n=0$}\label{fig:aa}
\end{subfigure}
\begin{subfigure}{0.4\textwidth}
\centering
\includegraphics[scale=0.45]{Figures/IncludePyramid_b_reverse.eps}
\caption{From $n=-1$ to $n=-2$}\label{fig:b}
\end{subfigure}
\qquad\qquad\qquad % spacing between the subfigures
\begin{subfigure}{0.4\textwidth}
\centering
\includegraphics[scale=0.45]{Figures/IncludePyramid_b.eps}
\caption{From $n=-2$ to $n=-1$}\label{fig:bb}
\end{subfigure}
\begin{subfigure}{0.4\textwidth}
\centering
\includegraphics[scale=0.45]{Figures/IncludePyramid_c_reverse.eps}
\caption{From $n=-2$ to $n=-3$}\label{fig:c}
\end{subfigure}
\qquad\qquad\qquad % spacing between the subfigures
\begin{subfigure}{0.4\textwidth}
\centering
\includegraphics[scale=0.45]{Figures/IncludePyramid_c.eps}
\caption{From $n=-3$ to $n=-2$}\label{fig:cc}
\end{subfigure}
\caption{Random walk on the Pascal pyramid} \label{fig:bratelli}
\end{figure}
\end{document}