我想将图 A 和 B 居中,同时将图 C 右对齐(作为图例)。我首先尝试通过 来实现这一点,但后来我认为通过或\hspace{}
可能可行。我很难实现这一点。有什么提示如何做到这一点?\hfill
\hfil
\documentclass[12pt,a4paper]{article}
\usepackage[latin1]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{graphicx}
\usepackage{subcaption}
\captionsetup[subfigure]{position=top, labelfont=bf}
\begin{document}
\begin{figure}[htpb]
\centering
\hfil
\subcaptionbox{A\label{fig:A}}{\includegraphics[width=2cm]{example-image-a}}
\subcaptionbox{B\label{B}}{\includegraphics[width=2cm]{example-image-b}}
\hfill
\subcaptionbox*{}{\includegraphics[width=2cm]{example-image-c}}
\end{figure}
\end{document}
答案1
\hfill
优先于\hfil
,因此用 替换\hfil
就\hfill
足以实现所需的输出:
\documentclass[12pt,a4paper]{article}
\usepackage[latin1]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{graphicx}
\usepackage{subcaption}
\captionsetup[subfigure]{position=top, labelfont=bf}
\begin{document}
\begin{figure}[htpb]
\centering
\hfill
\subcaptionbox{A\label{fig:A}}{\includegraphics[width=2cm]{example-image-a}}
\subcaptionbox{B\label{B}}{\includegraphics[width=2cm]{example-image-b}}
\hfill
\subcaptionbox*{}{\includegraphics[width=2cm]{example-image-c}}
\end{figure}
\end{document}
生产
编辑:要使 A 和 B 在整个页面的宽度上居中,而不是 C 未占用的空间,您可以使用\makebox
将 C 放入零宽度框中。以下是两者的比较:
\documentclass[12pt,a4paper]{article}
\usepackage[latin1]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{graphicx}
\usepackage{subcaption}
\captionsetup[subfigure]{position=top, labelfont=bf}
\begin{document}
\begin{figure}[htpb]
\centering
\hfill
\subcaptionbox{A\label{fig:A}}{\includegraphics[width=2cm]{example-image-a}}
\subcaptionbox{B\label{B}}{\includegraphics[width=2cm]{example-image-b}}
\hfill
\subcaptionbox*{}{\includegraphics[width=2cm]{example-image-c}}
\end{figure}
\begin{figure}[htpb]
\centering
\hfill
\subcaptionbox{A\label{fig:A}}{\includegraphics[width=2cm]{example-image-a}}
\subcaptionbox{B\label{B}}{\includegraphics[width=2cm]{example-image-b}}
\hfill
\makebox[0pt][r]{\subcaptionbox*{}{\includegraphics[width=2cm]{example-image-c}}}
\end{figure}
\end{document}
生产
\makebox
这里使用了两个可选参数:第一个指定框的宽度(0pt
),第二个指定框内容(即 C)在框内的对齐方式(r
,因此 C 的右边缘就是框所在的位置)。latexref.xyz有更多相关信息\makebox
。