我试图让第二行中较小的图像与第一行中较大的图像居中对齐:(使用 MS Word)
我尝试了以下代码:
\begin{figure*}[h]
\centering
\subcaptionbox{} [4em] {\includegraphics[width=8em]{4a.png}}\hfill
\subcaptionbox{} [4em] {\includegraphics[width=8em]{4b.png}}\hfill
\subcaptionbox{} [4em] {\includegraphics[width=8em]{4c.png}}\hfill
\subcaptionbox{} [4em] {\includegraphics[width=8em]{4d.png}}\hfill
\subcaptionbox{} [4em] {\includegraphics[width=8em]{4e.png}}\hfill
\subcaptionbox{} [4em] {\includegraphics[width=8em]{4f.png}}\\
\subcaptionbox{} [4em] {\includegraphics[width=4em]{4g.png}}\hfill
\subcaptionbox{} [4em] {\includegraphics[width=4em]{4h.png}}\hfill
\subcaptionbox{} [4em] {\includegraphics[width=4em]{4i.png}}\hfill
\subcaptionbox{} [4em] {\includegraphics[width=4em]{4j.png}}\hfill
\subcaptionbox{} [4em] {\includegraphics[width=4em]{4k.png}}\hfill
\subcaptionbox{} [4em] {\includegraphics[width=4em]{4l.png}}
\caption {My caption}
\end{figure*}
但是,如您所见,我必须手动调整 hspace 值,以使每个较小的图像与其对应的较大图像居中对齐。我该怎么做?
答案1
而是使用subcaption
包裹它允许您指定子图形块的宽度。以下是示例\subcaptionbox{<caption>}[<width>]{<stuff>}
:
\documentclass{article}
\usepackage{subcaption,graphicx}
\begin{document}
\begin{figure}
\centering
\subcaptionbox{}[4em]{\includegraphics[width=4em,angle=90]{example-image-a}}
\subcaptionbox{}[4em]{\includegraphics[width=4em,angle=90]{example-image-b}}
\subcaptionbox{}[4em]{\includegraphics[width=4em,angle=90]{example-image-c}}
\subcaptionbox{}[4em]{\includegraphics[width=4em,angle=90]{example-image-b}}
\subcaptionbox{}[4em]{\includegraphics[width=4em,angle=90]{example-image-a}}
\subcaptionbox{}[4em]{\includegraphics[width=4em]{example-image-a}}
\subcaptionbox{}[4em]{\includegraphics[width=4em]{example-image-b}}
\subcaptionbox{}[4em]{\includegraphics[width=4em]{example-image-c}}
\subcaptionbox{}[4em]{\includegraphics[width=4em]{example-image-b}}
\subcaptionbox{}[4em]{\includegraphics[width=4em]{example-image-a}}
\caption{My caption}
\end{figure}
\end{document}
如果你对(过时的)subfigure
,您可以测量最宽元素的宽度,然后将其用作较窄图像的宽度:
\newlength{\widestimg}
\begin{figure}
\centering
\settowidth{\widestimg}{\includegraphics{4a.png}}% Measure width of widest image
\subfigure[]{\includegraphics{4a.png}}
\subfigure[]{\includegraphics{4b.png}}
\subfigure[]{\includegraphics{4c.png}}
\subfigure[]{\includegraphics{4d.png}}
\subfigure[]{\includegraphics{4e.png}}
\subfigure[]{\includegraphics{4f.png}}
\subfigure[]{\makebox[\widestimg]{\includegraphics{4g.png}}}
\subfigure[]{\makebox[\widestimg]{\includegraphics{4h.png}}}
\subfigure[]{\makebox[\widestimg]{\includegraphics{4i.png}}}
\subfigure[]{\makebox[\widestimg]{\includegraphics{4j.png}}}
\subfigure[]{\makebox[\widestimg]{\includegraphics{4k.png}}}
\subfigure[]{\makebox[\widestimg]{\includegraphics{4l.png}}}
\caption{My caption}
\end{figure}