2

I would like to include a figure made by 2 or more subfigures. This is my code:

\begin{figure}[ht]
    \centering
    \begin{subfigure}[b]{0.3\textwidth}
        \includegraphics[width=\textwidth]{../figuras/fig1}
        \caption{Caption}
    \end{subfigure}
    \quad
    \begin{subfigure}[b]{0.3\textwidth}
        \includegraphics[width=\textwidth]{../figuras/fig2}
        \caption{Caption}
    \end{subfigure}
    \quad
    \begin{subfigure}[b]{0.3\textwidth}
        \includegraphics[width=\textwidth]{../figuras/fig3}
        \caption{Caption}
    \end{subfigure}
\caption{Caption}
\end{figure}

And I have imported the following packages:

\usepackage[latin1]{inputenc}
\usepackage{babel}
\usepackage{fancyhdr}
\usepackage{subcaption}
\usepackage{geometry}
\usepackage{makeidx}
\usepackage{graphicx}
\usepackage{latexsym}
\usepackage{amssymb}
\usepackage{eucal}
\usepackage{setspace}\singlespacing

I have this error in all \caption lines:

Missing \endcsname inserted. \caption{Caption} Extra \endcsname. \caption{Caption}

How can I fix it?

  • 2
    Please, make a small complete example of code that reproduces the problem. As far as I can see, the code will not break, with a standard class. – egreg Mar 19 at 10:21
1

in mwe (minimal working example) below i composed from yours code fragments, in which i made the following changes:

  • add demo option to graphicx (which generate black boxes instead of yours images which i haven't)
  • add package lipsum for dummy text in test document
  • replace \quad width \hfill which equidistantly place images between left and right text border
  • to code add some codes which may be helpful to you complete mwe (minimal working example) is:

    \documentclass[english]{book}
    % \usepackage[latin1]{inputenc} % better to use \usepackage[utf]{inputenc}
                                    % which is newest version of document classes default
    \usepackage{babel}
    \usepackage{fancyhdr}
    \usepackage{subcaption}
    \usepackage{geometry}
    \usepackage{makeidx}
    \usepackage[demo]{graphicx}         % in the real document remove option "demo"
    %\usepackage{latexsym}
    \usepackage{amssymb}
    \usepackage{eucal}
    %\usepackage{setspace}\singlespacing
    
    \usepackage{lipsum}                 % for dummy text, remove in the real document
    \begin{document}
    \lipsum[1-5]
        \begin{figure}[htb]
    %\centering
        \begin{subfigure}[b]{0.3\textwidth}
            \includegraphics[width=\linewidth]{../figuras/fig1}
            \caption{sub caption}
        \end{subfigure}
        \hfill
        \begin{subfigure}[b]{0.3\textwidth}
            \includegraphics[width=\linewidth]{../figuras/fig2}
            \caption{sub caption}
        \end{subfigure}
        \hfill
        \begin{subfigure}[b]{0.3\textwidth}
            \includegraphics[width=\linewidth]{../figuras/fig3}
            \caption{sub caption}
        \end{subfigure}
    \caption{Main caption}
        \end{figure}
    \lipsum[6-10]
    \end{document}
    

which gives:

enter image description here

from above mwe follows, that its code not cause any error. since log file of your document is unknown, it is difficult to say, from where is your error. for further help, please merge your document fragments in one small but complete document like in above mwe and add it to your question.

0

Hope this helps.

\documentclass[12pt,twoside]{book}
\usepackage[latin1]{inputenc}
\usepackage{babel}
\usepackage{fancyhdr}
\usepackage{subcaption}
\usepackage{geometry}
\usepackage{makeidx}
\usepackage{graphicx}
\usepackage{latexsym}
\usepackage{amssymb}
\usepackage{eucal}
\usepackage{setspace}
\singlespacing
\begin{document}
\begin{figure}[ht]
\centering
\begin{subfigure}[b]{0.3\textwidth}
    \includegraphics[width=\textwidth]{../figuras/fig1}
    \caption{Caption}
\end{subfigure}
\quad
\begin{subfigure}[b]{0.3\textwidth}
    \includegraphics[width=\textwidth]{../figuras/fig2}
    \caption{Caption}
\end{subfigure}
\quad
\begin{subfigure}[b]{0.3\textwidth}
    \includegraphics[width=\textwidth]{../figuras/fig3}
    \caption{Caption}
\end{subfigure}
\caption{Caption}
\end{figure}
\end{document}

I am getting the following output for your source code, as I am not having the images. The screenshot is attached for your reference.

enter image description here

Edit 2: Alternate Solution using SubFloat Environment (Figures with 13 Subfigures).

\documentclass[12pt,a4paper,twoside,onecolumn]{book}
\usepackage[latin1]{inputenc}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{graphicx}
\usepackage{subfig}
\begin{document}
\begin{figure*}
\mbox{\subfloat[]{\label{1} \includegraphics[height=2.3cm]{example-image-a}}}
\mbox{\subfloat[]{\label{2} \includegraphics[height=2.3cm]{example-image-b}}}
\mbox{\subfloat[]{\label{3} \includegraphics[height=2.3cm]{example-image-c}}}
\mbox{\subfloat[]{\label{4} \includegraphics[height=2.3cm]{example-image-b}}}
\mbox{\subfloat[]{\label{5} \includegraphics[height=2.3cm]{example-image-b}}}
\mbox{\subfloat[]{\label{6} \includegraphics[height=2.3cm]{example-image-c}}}
\mbox{\subfloat[]{\label{7} \includegraphics[height=2.3cm]{example-image-b}}}
\mbox{\subfloat[]{\label{8} \includegraphics[height=2.3cm]{example-image-b}}}
\mbox{\subfloat[]{\label{9} \includegraphics[height=2.3cm]{example-image-a}}}
\mbox{\subfloat[]{\label{10} \includegraphics[height=2.3cm]{example-image-b}}}
\mbox{\subfloat[]{\label{11} \includegraphics[height=2.3cm]{example-image-c}}}
\mbox{\subfloat[]{\label{12} \includegraphics[height=2.3cm]{example-image-b}}}
\mbox{\subfloat[]{\label{13} \includegraphics[height=2.3cm]{example-image-b}}}


\caption{Normal Models. \protect\subref{subfig:1} SLR. \protect\subref{subfig:2} MLR. \protect\subref{subfig:3} SWR. \protect\subref{subfig:4} OLS. \protect\subref{5} OLS. \protect\subref{6} OS. \protect\subref{7} Ok. \protect\subref{8} hi. \protect\subref{9} hey. \protect\subref{10} MSD. \protect\subref{11} LPY. \protect\subref{12} MSY. \protect\subref{13} Hello.}
\label{fig}
\end{figure*}
\end{document}
  • what did you change? It seems to be the same... – Sergio Cavero Mar 19 at 9:48
  • You run it. I am getting no error. I have added the \documentclass{article}, also I have embedded your code inside the \begin{document} \end{document} fragment. – Mishra S Mar 19 at 9:50
  • @Sergio See the edit in the answer. – Mishra S Mar 19 at 9:54
  • I see. However, I cant change the document class to article becouse I was using book. – Sergio Cavero Mar 19 at 9:56
  • Okay. Change \documentclass{book} from \documentclass{article}. The code will work. See my edit in the above answer. – Mishra S Mar 19 at 10:00

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.