2

I am using this

\begin{figure}[h!]
        \begin{subfigure}{\textwidth}
            \centering
            % include first image
            \includegraphics[width=1\linewidth]{chapter4/images/smoothingfruit1.eps} 
            \caption{A full range of typical \textit{fruit puree dataset} spectrum}
            \label{fig:sub-smoothingfruit}
        \end{subfigure}
        \begin{subfigure}{0.5\textwidth}

and give me this error:

enter image description here

I had also added in:

\usepackage{textcomp}
\usepackage{subcaption}

\usepackage[hypcap=false]{caption}
\usepackage[list=true]{subcaption}
1
  • 2
    It looks like you are missing the image that you want to use, not a package.
    – twsh
    Commented Mar 16, 2020 at 0:05

1 Answer 1

4

Every \begin should have an \end.

The correct code is as follows:

\documentclass{article}
\usepackage{graphicx}
\usepackage{subcaption}
%
\begin{document}
%
\begin{figure}[h!]
    \begin{subfigure}{\textwidth}
    \centering
    % include first image
    \includegraphics[width=1\linewidth]{test.jpg} % replace test.jpg with the path of figure of your liking.
    \caption{A full range of typical \textit{fruit puree dataset} spectrum}
    \label{fig:sub-smoothingfruit}
    \end{subfigure}
\end{figure}
%
\end{document}

The output would be like this:

enter image description here

As you didn't share the document class you are using, the standard article class was assumed. The subfigure is used by including \usepackage{subcaption} as you have been trying. Your code, however, suffers of two problems:

  1. You started \begin{figure}[h!], but you never closed it by \end{figure}.
  2. You started another \begin{subfigure}{0.5\textwidth} at the end of your code, never closed as well by \end{subfigure}.

You'd better use \usepackage{graphicx} in the preamble when adding graphics to your document.

You must log in to answer this question.

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