使用 minipage 时,图片会堆叠而不是并排显示

使用 minipage 时,图片会堆叠而不是并排显示

我试图将一个图形放在另外四个图形旁边,两个在上,两个在下。也就是说,一个图形在左侧,四个小图形在右侧(2 x 2)但每当我添加子标题时,它们最终都会堆叠在一起。

如果有人能帮助我,我将非常感激。谢谢!

\documentclass[]{article}
\usepackage[margin=0.8in]{geometry}
\usepackage{graphicx}
\usepackage{subcaption}    
\begin{document}   
\begin{figure}[ht!]
    \captionsetup{justification=centering}
    \centering
    \begin{minipage}{.49\linewidth}
        \centering
        \includegraphics[width=0.9\linewidth]{figfit22.png}
        \subcaption{Measured spacing as function of pitch}
    \end{minipage}
    \hfill
    \centering
    \begin{minipage}{.49\linewidth}
\centering
\includegraphics[width=0.31\linewidth]{dif42.png}\subcaption{Pitch: 24 $\mu$m}
\includegraphics[width=0.31\linewidth]{dif12.png}\subcaption{Pitch: 83 $\mu$m}
\includegraphics[width=0.31\linewidth]{dif22.png}\subcaption{Pitch: 125 $\mu$m}
\includegraphics[width=0.31\linewidth]{dif32.png}\subcaption{Pitch: 250 $\mu$m}
    \end{minipage}
\end{figure}
\end{document}

答案1

改用\subcaptionbox{<caption>}{<image>}。请注意手册中的警告subcaption

请注意\subcaption命令必须可以在其自己的盒子或环境内应用。

所以使用时\subcaption,每个都必须有自己的minipage或类似的。\subcaptionbox你不需要那个。

(由于我没有您的图像,因此我添加了选项demographicx您需要删除它。)

代码输出

\documentclass[]{article}
\usepackage[margin=0.8in]{geometry}
\usepackage[demo]{graphicx}
\usepackage{subcaption}    
\begin{document}   
\begin{figure}[ht!]
    \captionsetup{justification=centering}
    \centering
    \begin{minipage}{.49\linewidth}
        \centering
        \includegraphics[width=0.9\linewidth]{figfit22.png}
        \subcaption{Measured spacing as function of pitch}
    \end{minipage}
    \hfill
    \begin{minipage}{.49\linewidth}
\centering
\subcaptionbox{Pitch: 24 $\mu$m}{\includegraphics[width=0.31\linewidth]{dif42.png}}
\subcaptionbox{Pitch: 83 $\mu$m}{\includegraphics[width=0.31\linewidth]{dif12.png}}

\subcaptionbox{Pitch: 125 $\mu$m}{\includegraphics[width=0.31\linewidth]{dif22.png}}
\subcaptionbox{Pitch: 250 $\mu$m}{\includegraphics[width=0.31\linewidth]{dif32.png}}
    \end{minipage}
\end{figure}
\end{document}

相关内容