TransWikia.com

Error using subfloat and centerline in figure

TeX - LaTeX Asked by Farnaz on May 28, 2021

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}
defx{{mathbf x}}
defL{{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., `Ihbox'). Otherwise just continue,
and I'll forget about whatever was undefined.

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

2 Answers

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.16linewidth}
includegraphics[width=1textwidth]{420}
caption*{420}
end{subfigure}hfill
begin{subfigure}{0.16linewidth}
includegraphics[width=1textwidth]{421}
caption*{421}
end{subfigure}hfill
begin{subfigure}{0.16linewidth}
includegraphics[width=1textwidth]{422}
caption*{422}
end{subfigure}hfill
begin{subfigure}{0.16linewidth}
includegraphics[width=1textwidth]{423}
caption*{423}
end{subfigure}hfill
begin{subfigure}{0.16linewidth}
includegraphics[width=1textwidth]{424}
caption*{424}
end{subfigure}hfill
begin{subfigure}{0.16linewidth}
includegraphics[width=1textwidth]{425}
caption*{425}
end{subfigure}
end{figure}%
begin{figure}[!htb]
    captionsetup[subfigure]{font=bf}
    begin{subfigure}{0.16linewidth}
        includegraphics[width=1textwidth]{420}
        caption*{420}
    end{subfigure}hfill
    begin{subfigure}{0.16linewidth}
        includegraphics[width=1textwidth]{421}
        caption*{421}
    end{subfigure}hfill
    begin{subfigure}{0.16linewidth}
        includegraphics[width=1textwidth]{422}
        caption*{422}
    end{subfigure}hfill
    begin{subfigure}{0.16linewidth}
        includegraphics[width=1textwidth]{423}
        caption*{423}
    end{subfigure}hfill
    begin{subfigure}{0.16linewidth}
        includegraphics[width=1textwidth]{424}
        caption*{424}
    end{subfigure}hfill
    begin{subfigure}{0.16linewidth}
        includegraphics[width=1textwidth]{425}
        caption*{425}
    end{subfigure}
end{figure}%
begin{figure}[!htb]
    captionsetup[subfigure]{font=bf}
    begin{subfigure}{0.16linewidth}
        includegraphics[width=1textwidth]{420}
        caption*{420}
    end{subfigure}hfill
    begin{subfigure}{0.16linewidth}
        includegraphics[width=1textwidth]{421}
        caption*{421}
    end{subfigure}hfill
    begin{subfigure}{0.16linewidth}
        includegraphics[width=1textwidth]{422}
        caption*{422}
    end{subfigure}hfill
    begin{subfigure}{0.16linewidth}
        includegraphics[width=1textwidth]{423}
        caption*{423}
    end{subfigure}hfill
    begin{subfigure}{0.16linewidth}
        includegraphics[width=1textwidth]{424}
        caption*{424}
    end{subfigure}hfill
    begin{subfigure}{0.16linewidth}
        includegraphics[width=1textwidth]{425}
        caption*{425}
    end{subfigure}
end{figure}%
begin{figure}[!htb]
    captionsetup[subfigure]{font=bf}
    begin{subfigure}{0.16linewidth}
        includegraphics[width=1textwidth]{420}
        caption*{420}
    end{subfigure}hfill
    begin{subfigure}{0.16linewidth}
        includegraphics[width=1textwidth]{421}
        caption*{421}
    end{subfigure}hfill
    begin{subfigure}{0.16linewidth}
        includegraphics[width=1textwidth]{422}
        caption*{422}
    end{subfigure}hfill
    begin{subfigure}{0.16linewidth}
        includegraphics[width=1textwidth]{423}
        caption*{423}
    end{subfigure}hfill
    begin{subfigure}{0.16linewidth}
        includegraphics[width=1textwidth]{424}
        caption*{424}
    end{subfigure}hfill
    begin{subfigure}{0.16linewidth}
        includegraphics[width=1textwidth]{425}
        caption*{425}
    end{subfigure}
end{figure}
end{document}

Answered by js bibra on May 28, 2021

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}
renewcommandShowFrameLinethickness{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

Answered by Zarko on May 28, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP