0

I would like to add four figures into a single row but I am unable to do it. I tried a lot to figure out the error but still failed. At the moment, there is one figure on row 1, the second figure on row two, third figure and fourth figure are on row 4.

\begin{figure}
%\centering
    %\hfill
    \subfigure[Training         loss]{\includegraphics[width=0.25\linewidth]{images/all_vits.pdf}}
%\vspace{-4pt}
%\hfill
\subfigure[Accuracy]{\includegraphics[width=0.25\linewidth]{images/acc_vit.pdf}}

% %\vspace{-4pt} %\hfill %\caption{Comparison of pure ViTs and Convolutional ViTs %models.} %\vspace{-13pt} %\label{fig:ALLVITS} %\end{figure} %\begin{figure}

%\hfill
\subfigure[Training loss]{\includegraphics[width=0.25\linewidth]{images/ours_loss.pdf}}
%\vspace{-4pt}
%\hfill
\subfigure[Accuracy]{\includegraphics[width=0.25\linewidth]{images/ours_acc.pdf}}
%\vspace{-4pt}
%\hfill
%\caption{Comparison of our module integrates in O-PVT.}
\label{fig:OPVT}

\end{figure}

Khawar Islam
  • 175
  • 1
  • 8

2 Answers2

4

For more information see Figures: What is the difference between using subfig or subfigure. Make sure that the sum of the width is less than 100 %. BTW, your code looks kind of messy. I recommend keeping it tidy, see the proposal below.

\documentclass{article}
\usepackage{graphicx}
\usepackage{subfig}

\begin{document}

\begin{figure} \centering \subfloat[First.]{\label{4figs-a} \includegraphics[width=0.20\textwidth]{example-image-a}}% The "%" masks the line break. \hfill \subfloat[Second.]{\label{4figs-b} \includegraphics[width=0.20\textwidth]{example-image-a}}% \hfill \subfloat[Third.]{\label{4figs-c} \includegraphics[width=0.20\textwidth]{example-image-a}}% \hfill \subfloat[Forth.]{\label{4figs-d} \includegraphics[width=0.20\textwidth]{example-image-a}}% \caption{Four sub-floats.} \label{4figs} \end{figure}

See \figurename~\ref{4figs-b} and \figurename~\ref{4figs-d}.

\end{document}

enter image description here

  • Now, four figures are in one row but it gives an error "LaTeX Error: No counter 'subfigure@save' defined." Also, on the next page, the gap between the caption and table is overlap each other. – Khawar Islam Apr 05 '22 at 07:23
  • This is why you need to provide a better MWE. Otherwise, we cannot know your situation. – Dr. Manuel Kuehner Apr 05 '22 at 12:35
-2

In my case, the below code is worked fine.

\begin{figure}[t]
    \subfigure[Training loss curves]{\includegraphics[width=0.245\linewidth]{images/all.pdf}}
    \subfigure[Accuracy curves]{\includegraphics[width=0.245\linewidth]{images/all.pdf}}
    \label{fig:ALLVITS}
    \subfigure[Training loss curves]{\includegraphics[width=0.245\linewidth]{images/all.pdf}}
    \subfigure[Accuracy curves]{\includegraphics[width=0.245\linewidth]{images/all.pdf}}
    \caption{Comparison of our module integrates in O-PVT.}
    \label{fig:OPVT}
\end{figure}
Khawar Islam
  • 175
  • 1
  • 8
  • 3
    Could you please add more details to your answer? You can find more information on how to write good answers in the help center. – Claudio Fiandrino Apr 05 '22 at 12:46
  • 2
    When posting questions and answers, please provide MWEs https://tex.meta.stackexchange.com/questions/228/ive-just-been-asked-to-write-a-minimal-working-example-mwe-what-is-that – FHZ Apr 05 '22 at 13:25