我想以特殊的顺序和布局放置一些图形。我尝试使用以下方法分隔一个“列”vrule
正如您在此处看到的,vrule 没有在两个位置上对齐,但对我来说,width
两个“行”的设置看起来相同。
这是我正在使用的代码:
\documentclass{article}
\usepackage{graphicx}
\usepackage{caption}
\usepackage{subfig}
\begin{document}
\begin{figure} [h]
\centering\renewcommand{\thesubfigure}{a}
\subfloat[A Text]{
\includegraphics[width=0.28\textwidth]
{example-image}}
\hspace{0.03\textwidth} \renewcommand{\thesubfigure}{b}
\subfloat[B Text]{
\includegraphics[width=0.28\textwidth]
{example-image}}
\hspace{0.03\textwidth} \vrule\ \hspace{0.015\textwidth} \renewcommand{\thesubfigure}{e}
\subfloat[E Text]{
\includegraphics[width=0.28\textwidth]
{example-image}}
\renewcommand{\thesubfigure}{c}
\subfloat[C Text]{
\includegraphics[width=0.28\textwidth]
{example-image}}
\hspace{0.03\textwidth}\renewcommand{\thesubfigure}{d}
\subfloat[D Text]{
\includegraphics[width=0.28\textwidth]
{example-image}}
\hspace{0.03\textwidth} \vrule\ \hspace{0.015\textwidth} \renewcommand{\thesubfigure}{f}
\subfloat[F Text]{
\includegraphics[width=0.28\textwidth]
{example-image}}
\captionof{figure}[]{A-F Text}
\end{figure}
\end{document}
有什么建议为什么它没有对齐吗?
答案1
您必须注意不要在代码中插入不必要的空格。它们是错误对齐的原因。我插入了一些 % 以确保每行末尾没有空格。
\documentclass{article}
\usepackage{graphicx}
\usepackage{caption}
\usepackage{subfig}
\begin{document}
\begin{figure} [h]
\centering\renewcommand{\thesubfigure}{a}%
\subfloat[A Text]{%
\includegraphics[width=0.28\textwidth]%
{example-image}}%
\hspace{0.03\textwidth}\renewcommand{\thesubfigure}{b}%
\subfloat[B Text]{%
\includegraphics[width=0.28\textwidth]%
{example-image}}%
\hspace{0.03\textwidth}\vrule\
\hspace{0.015\textwidth}\renewcommand{\thesubfigure}{e}%
\subfloat[E Text]{%
\includegraphics[width=0.28\textwidth]%
{example-image}}%
\renewcommand{\thesubfigure}{c}%
\subfloat[C Text]{%
\includegraphics[width=0.28\textwidth]%
{example-image}}%
\hspace{0.03\textwidth}\renewcommand{\thesubfigure}{d}%
\subfloat[D Text]{%
\includegraphics[width=0.28\textwidth]%
{example-image}}%
\hspace{0.03\textwidth}\vrule\
\hspace{0.015\textwidth}\renewcommand{\thesubfigure}{f}%
\subfloat[F Text]{%
\includegraphics[width=0.28\textwidth]%
{example-image}}%
\captionof{figure}[]{A-F Text}
\end{figure}
\end{document}
我认为更简单的解决方案是使用表格来处理对齐、间距和垂直规则。
\documentclass{article}
\usepackage{graphicx}
\usepackage{caption}
\usepackage{subfig}
\begin{document}
\begin{figure} [h]
\begin{tabular}{c c | c}
\subfloat[A Text]{\includegraphics[width=0.28\textwidth]{example-image}} &
\subfloat[B Text]{\includegraphics[width=0.28\textwidth]{example-image}} &
\subfloat[C Text]{\includegraphics[width=0.28\textwidth]{example-image}} \\
\subfloat[D Text]{\includegraphics[width=0.28\textwidth]{example-image}} &
\subfloat[E Text]{\includegraphics[width=0.28\textwidth]{example-image}} &
\subfloat[F Text]{\includegraphics[width=0.28\textwidth]{example-image}} \\
\end{tabular}
\captionof{figure}[]{A-F Text}
\end{figure}
\end{document}
答案2
我建议采用一种与 Georg 的方法类似的不同方法,但避免了使用计数器的需要。
嵌套表格将确保编号正确。
\documentclass{article}
\usepackage{graphicx}
\usepackage{caption}
\usepackage{subfig}
\begin{document}
\begin{figure}[htp] % <--- not only h
\centering
\begin{tabular}{@{}c|c@{}}
\begin{tabular}{@{}cc@{}}
\subfloat[A Text]{%
\includegraphics[width=0.28\textwidth]{example-image}%
}
&
\subfloat[B Text]{%
\includegraphics[width=0.28\textwidth]{example-image}%
}
\\
\subfloat[C Text]{%
\includegraphics[width=0.28\textwidth]{example-image}%
}
&
\subfloat[D Text]{%
\includegraphics[width=0.28\textwidth]{example-image}%
}
\end{tabular}
&
\begin{tabular}{@{}c@{}}
\subfloat[E Text]{%
\includegraphics[width=0.28\textwidth]{example-image}%
}
\\
\subfloat[F Text]{%
\includegraphics[width=0.28\textwidth]{example-image}%
}
\end{tabular}
\end{tabular}
\caption{A-F Text}
\end{figure}
\end{document}