2

I have this code to place six images into two rows (3 images for each row):

\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}

But they are shown in vertical positions.

4
  • Please always make sure to post full but miniaml examples such that others know which class and packages you are using. Also use images from ctan.org/tex-archive/macros/latex/contrib/mwe, as we of course does not have your images.
    – daleif
    Apr 22 at 9:23
  • 4
    Remember that a blank line gives a new paragraph. So \hfill and then a blanmk line is a bad idea.
    – daleif
    Apr 22 at 9:26
  • @daleif thank you so much. It solves my issue. I did not know that a blank line in the code will be an issue. By removing the blank lines, it is solved. Apr 22 at 9:31
  • You can always start a line with % and leave the rest blank. The is also \@bsphack and \@esphack for removal with extreme prejudice. Apr 22 at 15:33

1 Answer 1

6

This works just fine. Be careful with your blank lines, that starts a new paragraph, so they should not be there for the lines that ends with \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}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .