我有以下程式碼將六個圖像放入兩行(每行 3 個圖像):
\begin{figure}[htbp!]
\centering
\begin{subfigure}[b]{0.3 \textwidth}
\includegraphics[width=\textwidth]{1agw-eva.png}
\caption{Cec\_2021\_ Function 1}
\end{subfigure} \hfill
\begin{subfigure}[b]{0.3\textwidth}
\includegraphics[width=\textwidth]{2agw-eva.png}
\caption{Cec\_2021\_ Function 2}
\end{subfigure} \hfill
\begin{subfigure}[b]{0.3\textwidth}
\includegraphics[width=\textwidth]{3agw-eva.png}
\caption{Cec\_2021\_ Function 3}
\end{subfigure}
\begin{subfigure}[b]{0.3\textwidth}
\includegraphics[width=\textwidth]{4agw-eva.png}
\caption{Cec\_2021\_ Function 5}
\end{subfigure} \hfill
\begin{subfigure}[b]{0.3\textwidth}
\includegraphics[width=\textwidth]{5agw-eva.png}
\caption{Cec\_2021\_ Function 7}
\end{subfigure} \hfill
\begin{subfigure}[b]{0.3\textwidth}
\centering
\includegraphics[width=\textwidth]{6agw-eva.png}
\caption{Cec\_2021\_ Function 8}
\end{subfigure}
\hfill
\begin{subfigure}[t]{0.9\textwidth}
\centering
\includegraphics[width=\textwidth]{7agw-eva.png}
\caption{Cec\_2021\_ Function 3}
\end{subfigure}
\caption{caption.}
\label{fig:fig-evaluation}
\end{figure}
但它們以垂直位置顯示。
答案1
這很好用。小心你的空白行,它開始一個新的段落,所以它們不應該出現在以 結尾的行中\hfill
。
\documentclass[a4paper]{article}
\usepackage{subcaption}
\usepackage{graphicx}
\begin{document}
\begin{figure}[htbp!]
\centering
\begin{subfigure}[b]{0.3 \textwidth}
\includegraphics[width=\textwidth]{example-image}
\caption{Cec\_2021\_ Function 1}
\end{subfigure} \hfill
\begin{subfigure}[b]{0.3\textwidth}
\includegraphics[width=\textwidth]{example-image}
\caption{Cec\_2021\_ Function 2}
\end{subfigure} \hfill
\begin{subfigure}[b]{0.3\textwidth}
\includegraphics[width=\textwidth]{example-image}
\caption{Cec\_2021\_ Function 3}
\end{subfigure}
\medskip
\begin{subfigure}[b]{0.3\textwidth}
\includegraphics[width=\textwidth]{example-image}
\caption{Cec\_2021\_ Function 5}
\end{subfigure} \hfill
\begin{subfigure}[b]{0.3\textwidth}
\includegraphics[width=\textwidth]{example-image}
\caption{Cec\_2021\_ Function 7}
\end{subfigure} \hfill
\begin{subfigure}[b]{0.3\textwidth}
\centering \includegraphics[width=\textwidth]{example-image}
\caption{Cec\_2021\_ Function 8}
\end{subfigure}
\medskip
\begin{subfigure}[t]{0.9\textwidth}
\centering \includegraphics[width=\textwidth]{example-image}
\caption{Cec\_2021\_ Function 3}
\end{subfigure}
\caption{Convergence curves for AGWO and other recent algorithms
during 2500 iterations.}
\label{fig:agwo-evaluation}
\end{figure}
\end{document}