2

I would like to have 6 figures side by side and I have 4 series of these figures. I have the following latex code:

\documentclass{article}
\usepackage{spconf,amsmath,graphicx}
\usepackage{romannum}
\def\x{{\mathbf x}}
\def\L{{\cal L}}
\begin{document}
\begin{figure}[htb]
    \centerline{
    \subfloat{\includegraphics[width=1cm]{example-image.png}}\hspace{0.6mm}%
    \subfloat{\includegraphics[width = 1cm]{example-image.png}}\hspace{0.6mm}%
    \subfloat{\includegraphics[width = 1cm]{example-image.png}}\hspace{0.6mm}%
    \subfloat{\includegraphics[width = 1cm]{example-image.png}}\hspace{0.6mm}%
    \subfloat{\includegraphics[width = 1cm]{example-image.png}}\hspace{0.6mm}%
    \subfloat{\includegraphics[width = 1cm]{example-image.png}}\hspace{0.6mm}%
    \subfloat{\includegraphics[width = 1cm]{example-image.png}}\hspace{0.6mm}%
    \subfloat{\includegraphics[width = 1cm]{img/Amp/340_GT.png}}\\}
    \centerline{
    \subfloat{\includegraphics[width = 1cm]{example-image.png}}\hspace{0.6mm}%
    \subfloat{\includegraphics[width = 1cm]{example-image.png}}\hspace{0.6mm}%
    \subfloat{\includegraphics[width = 1cm]{example-image.png}}\hspace{0.6mm}%
    \subfloat{\includegraphics[width = 1cm]{example-image.png}}\hspace{0.6mm}%
    \subfloat{\includegraphics[width = 1cm]{example-image.png}}\hspace{0.6mm}%
    \subfloat{\includegraphics[width = 1cm]{example-image.png}}\hspace{0.6mm}%
    \subfloat{\includegraphics[width = 1cm]{example-image.png}}\hspace{0.6mm}%
    \subfloat{\includegraphics[width = 1cm]{example-image.png}}\\}
    \centerline{
    \subfloat{\includegraphics[width = 1cm]{example-image.png}}\hspace{0.6mm}%
    \subfloat{\includegraphics[width = 1cm]{example-image.png}}\hspace{0.6mm}%
    \subfloat{\includegraphics[width = 1cm]{example-image.png}}\hspace{0.6mm}%
    \subfloat{\includegraphics[width = 1cm]{example-image.png}}\hspace{0.6mm}%
    \subfloat{\includegraphics[width = 1cm]{example-image.png}}\hspace{0.6mm}%
    \subfloat{\includegraphics[width = 1cm]{example-image.png}}\hspace{0.6mm}%
    \subfloat{\includegraphics[width = 1cm]{example-image.png}}\hspace{0.6mm}%
    \subfloat{\includegraphics[width = 1cm]{img/Amp/601_GT.png}}\\}
    \centerline{
    \subfloat{\includegraphics[width = 1cm]{example-image.png}}\hspace{0.6mm}%
    \subfloat{\includegraphics[width = 1cm]{example-image.png}}\hspace{0.6mm}%
    \subfloat{\includegraphics[width = 1cm]{example-image.png}}\hspace{0.6mm}%
    \subfloat{\includegraphics[width = 1cm]{example-image.png}}\hspace{0.6mm}%
    \subfloat{\includegraphics[width = 1cm]{example-image.png}}\hspace{0.6mm}%
    \subfloat{\includegraphics[width = 1cm]{example-image.png}}\hspace{0.6mm}%
    \subfloat{\includegraphics[width = 1cm]{img/Fourth/289_PR.png}}\hspace{0.6mm}%
    \subfloat{\includegraphics[width = 1cm]{example-image.png}}\\}
    \caption{caption}
    \label{fig: Sos Prediction}
\end{figure}
\end{document}

The figures are shown correctly but I get errors at last subfloat of each line:

undefined control sequence

and

{\includegraphics [width=1cm]{example-image.png}}...
l.323 ...hics[width = 1cm]{example-image.png}}\\}
                                                  
The control sequence at the end of the top line
of your error message was never \def'ed. If you have
misspelled it (e.g., `\hobx'), type `I' and the correct
spelling (e.g., `I\hbox'). Otherwise just continue,
and I'll forget about whatever was undefined.

I can not figure out why this error appears, any ideas?

5
  • Welcome to TEX.SE! Please provide a full minimal working example which reproduces the issue, starting with \documentclass{...} and ending with \end{document}. And please replace all your figures (which we do not have) by example-image. Furthermore, TeX breaks the line at the undefined control sequence, so preserving linebreaks when quoting error messages is crucial. – campa Oct 14 '20 at 7:54
  • 2
    \subfloat is provided by the package subfig but you don't load this package. – user205700 Oct 14 '20 at 8:06
  • @Famaz please have a look at the answer below – js bibra Oct 14 '20 at 14:42
  • 1
    @jsbibra Thanks for your response but the main problem was what P.M. mentioned. I didn't add subfig package! – Farnaz Oct 14 '20 at 15:36
  • Don't use \\ in \centerline{...} as it adds a second line. Use \centering (no argument) instead. BTW, the subcaption package also has a version of \subfloat.. – John Kormylo Oct 14 '20 at 17:45
1

This may point you in correct direction

enter image description here

\documentclass[demo]{article} % remove 'demo' option in real document
\usepackage{graphicx,subcaption}
\begin{document}
\begin{figure}[!htb]
\captionsetup[subfigure]{font=bf}
\begin{subfigure}{0.16\linewidth}
\includegraphics[width=1\textwidth]{420}
\caption*{420}
\end{subfigure}\hfill
\begin{subfigure}{0.16\linewidth}
\includegraphics[width=1\textwidth]{421}
\caption*{421}
\end{subfigure}\hfill
\begin{subfigure}{0.16\linewidth}
\includegraphics[width=1\textwidth]{422}
\caption*{422}
\end{subfigure}\hfill
\begin{subfigure}{0.16\linewidth}
\includegraphics[width=1\textwidth]{423}
\caption*{423}
\end{subfigure}\hfill
\begin{subfigure}{0.16\linewidth}
\includegraphics[width=1\textwidth]{424}
\caption*{424}
\end{subfigure}\hfill
\begin{subfigure}{0.16\linewidth}
\includegraphics[width=1\textwidth]{425}
\caption*{425}
\end{subfigure}
\end{figure}%
\begin{figure}[!htb]
    \captionsetup[subfigure]{font=bf}
    \begin{subfigure}{0.16\linewidth}
        \includegraphics[width=1\textwidth]{420}
        \caption*{420}
    \end{subfigure}\hfill
    \begin{subfigure}{0.16\linewidth}
        \includegraphics[width=1\textwidth]{421}
        \caption*{421}
    \end{subfigure}\hfill
    \begin{subfigure}{0.16\linewidth}
        \includegraphics[width=1\textwidth]{422}
        \caption*{422}
    \end{subfigure}\hfill
    \begin{subfigure}{0.16\linewidth}
        \includegraphics[width=1\textwidth]{423}
        \caption*{423}
    \end{subfigure}\hfill
    \begin{subfigure}{0.16\linewidth}
        \includegraphics[width=1\textwidth]{424}
        \caption*{424}
    \end{subfigure}\hfill
    \begin{subfigure}{0.16\linewidth}
        \includegraphics[width=1\textwidth]{425}
        \caption*{425}
    \end{subfigure}
\end{figure}%
\begin{figure}[!htb]
    \captionsetup[subfigure]{font=bf}
    \begin{subfigure}{0.16\linewidth}
        \includegraphics[width=1\textwidth]{420}
        \caption*{420}
    \end{subfigure}\hfill
    \begin{subfigure}{0.16\linewidth}
        \includegraphics[width=1\textwidth]{421}
        \caption*{421}
    \end{subfigure}\hfill
    \begin{subfigure}{0.16\linewidth}
        \includegraphics[width=1\textwidth]{422}
        \caption*{422}
    \end{subfigure}\hfill
    \begin{subfigure}{0.16\linewidth}
        \includegraphics[width=1\textwidth]{423}
        \caption*{423}
    \end{subfigure}\hfill
    \begin{subfigure}{0.16\linewidth}
        \includegraphics[width=1\textwidth]{424}
        \caption*{424}
    \end{subfigure}\hfill
    \begin{subfigure}{0.16\linewidth}
        \includegraphics[width=1\textwidth]{425}
        \caption*{425}
    \end{subfigure}
\end{figure}%
\begin{figure}[!htb]
    \captionsetup[subfigure]{font=bf}
    \begin{subfigure}{0.16\linewidth}
        \includegraphics[width=1\textwidth]{420}
        \caption*{420}
    \end{subfigure}\hfill
    \begin{subfigure}{0.16\linewidth}
        \includegraphics[width=1\textwidth]{421}
        \caption*{421}
    \end{subfigure}\hfill
    \begin{subfigure}{0.16\linewidth}
        \includegraphics[width=1\textwidth]{422}
        \caption*{422}
    \end{subfigure}\hfill
    \begin{subfigure}{0.16\linewidth}
        \includegraphics[width=1\textwidth]{423}
        \caption*{423}
    \end{subfigure}\hfill
    \begin{subfigure}{0.16\linewidth}
        \includegraphics[width=1\textwidth]{424}
        \caption*{424}
    \end{subfigure}\hfill
    \begin{subfigure}{0.16\linewidth}
        \includegraphics[width=1\textwidth]{425}
        \caption*{425}
    \end{subfigure}
\end{figure}
\end{document}
1

After half of year ... Since your main problem is solved by @P.M. comment, here are some off-topic suggestion how you can correct/improve your MWE:

  • because all images has the same width, you can use common settings for it by \setkeys{Gin}{...}
  • for centering of images on page is better than \centerline{...} to use command \centering
  • for starting new row of images just insert empty
  • instead of fix distance between image used \hfil
\documentclass{article}
\usepackage{graphicx}
\usepackage{subfig}

%---------------- show page layout. don't use in a real document!
\usepackage{showframe}
\renewcommand\ShowFrameLinethickness{0.15pt}
\renewcommand*\ShowFrameColor{\color{red}}
%---------------------------------------------------------------%
\begin{document}
\begin{figure}[htb]
\centering
\setkeys{Gin}{width=13mm}
    \subfloat{\includegraphics{example-image}}\hfil%
    \subfloat{\includegraphics{example-image}}\hfil%
    \subfloat{\includegraphics{example-image}}\hfil%
    \subfloat{\includegraphics{example-image}}\hfil%
    \subfloat{\includegraphics{example-image}}\hfil%
    \subfloat{\includegraphics{example-image}}\hfil%
    \subfloat{\includegraphics{example-image}}\hfil%
    \subfloat{\includegraphics{example-image}}

    \subfloat{\includegraphics{example-image}}\hfil%
    \subfloat{\includegraphics{example-image}}\hfil%
    \subfloat{\includegraphics{example-image}}\hfil%
    \subfloat{\includegraphics{example-image}}\hfil%
    \subfloat{\includegraphics{example-image}}\hfil%
    \subfloat{\includegraphics{example-image}}\hfil%
    \subfloat{\includegraphics{example-image}}\hfil%
    \subfloat{\includegraphics{example-image}}

    \subfloat{\includegraphics{example-image}}\hfil%
    \subfloat{\includegraphics{example-image}}\hfil%
    \subfloat{\includegraphics{example-image}}\hfil%
    \subfloat{\includegraphics{example-image}}\hfil%
    \subfloat{\includegraphics{example-image}}\hfil%
    \subfloat{\includegraphics{example-image}}\hfil%
    \subfloat{\includegraphics{example-image}}\hfil%
    \subfloat{\includegraphics{example-image}}

    \subfloat{\includegraphics{example-image}}\hfil%
    \subfloat{\includegraphics{example-image}}\hfil%
    \subfloat{\includegraphics{example-image}}\hfil%
    \subfloat{\includegraphics{example-image}}\hfil%
    \subfloat{\includegraphics{example-image}}\hfil%
    \subfloat{\includegraphics{example-image}}\hfil%
    \subfloat{\includegraphics{example-image}}\hfil%
    \subfloat{\includegraphics{example-image}}
\caption{caption}
    \label{fig: Sos Prediction}
\end{figure}
\end{document}

enter image description here

2
  • It is very nice as an answer. Probablily it is useful for me. My best regards. – Sebastiano Mar 13 at 22:20
  • 1
    @Sebastiano, thank you very much! – Zarko Mar 13 at 22:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.