# How to include images and figures in elsarticle document class

I used elsarticle document class

\documentclass[preprint,11pt,3p,authoryear]{elsarticle}


I try to include image inside. The document is running with out any error put the image was not appear. I used the following:

\documentclass[preprint,11pt,3p,authoryear]{elsarticle}
\usepackage{amsmath}
\numberwithin{equation}{section}
\usepackage{amssymb}
\usepackage{multicol}
\usepackage{natbib}
\usepackage{graphicx}
\usepackage{subfig}
\usepackage{subcaption}

\begin{document}

\begin{frontmatter}

\title{Title}\author[label1,label2]{Author1\fnref{label3}\corref{cor1}}

\address[label1]{ Address1}
\address[label2]{Address2}
\address[label3]{Address3}
\cortext[cor1]{Corresponding author}
\author[label1]{Author\fnref{label2}}
\author[label2]{Author3}
\author[label2]{Author4}

\begin{abstract}
Sample text. Sample text. Sample text. Sample text. Sample text. Sample text.
\end{abstract}

\begin{keyword}
keyword1
keyword2
keyword3
keyword4
keyword5
\end{keyword}
\end{frontmatter}

\begin{multicols}{2}

%% main text
\section{Introduction}
\label{sec1}

Sample text. Sample text. Sample text. Sample text. Sample text. Sample text.

\begin{figure}[!ht]
\centering

\begin{subfigure}[b]{0.49\columnwidth}
\includegraphics[width=columnwidth]{image1}
\caption{ image 1}
\label{fig1.1.a}
\end{subfigure}

\begin{subfigure}[b]{0.49\columnwidth}
\centering
\includegraphics[width=columnwidth]{image2}
\caption{image 2}
\label{fig1.1.b}
\end{subfigure}

\caption{image 1 and 2}
\label{fig1.1}
\end{figure}
\section{Related work}
Sample text. Sample text. Sample text. Sample text. Sample text. Sample text.

\section{The research problem and contributions of this study}
Sample text. Sample text. Sample text. Sample text. Sample text. Sample text.
\section{Materials}
Sample text. Sample text. Sample text. Sample text. Sample text. Sample text.

\section{Method}
Sample text. Sample text. Sample text. Sample text. Sample text. Sample text.

\end{multicols}
\end{document}


My question is: Is there any specific format to include figures inside the elsarticle format document because I use the same example with report format and it was work properly.

\documentclass[12pt,a4paper]{report}


Note: the images format is PDF format and there are existing I the same folder of the text file.

• Welcome to TeX.SX! I can't reproduce your problem, with your code (when trying with the subcaption package). Please make your code compilable, or at least complete it with \documentclass{...}, the required \usepackage's, \begin{document}, and \end{document}. – TonioElGringo Jul 27 '17 at 9:58
• Hi TonioElGringo I update the example with complete codes – user3346768 Jul 27 '17 at 12:19

## 2 Answers

When you compile the given example, you can see TeX is warning you that something is amiss:

Package multicol Warning: Floats and marginpars not allowed inside multicols'
environment!.


Since the figure is a float, you can't use it inside the multicols environment. You could insert your figure as a non-float using the float package and the H option.

With the elsarticle class, however, you should use the twocolumn class option to have a two column layout:

\documentclass[preprint,11pt,3p,authoryear,twocolumn]{elsarticle}


and get rid of the multicol package.

• Thank you TonioElGringo very much for your answer but there is another problem when I use subfigure inside one figure: LaTeX Error: Environment subfigure undefined. However \usepackege{subfig} was included. – user3346768 Jul 27 '17 at 12:53
• I think the subcaption package in now recommanded for subfigures. – TonioElGringo Jul 27 '17 at 13:11
• It also not working I updated the codes using subfigure thank yoy for any help TonioElGringo. – user3346768 Jul 27 '17 at 13:49

The above accepted answer solved the problem of including one figure in elsarticle class document, while I find the following answer which solve the problem of including subfigures Resize figures using subfloat environment in elsarticle class That I need to include the following packages:

\usepackage[pdftex]{color}
\usepackage[font=footnotesize,labelfont=bf]{caption}


then the codes will work properly as follows:

\documentclass[preprint, 3p, number]{elsarticle}
\usepackage[pdftex]{color}
\usepackage[font=footnotesize,labelfont=bf]{caption}
\usepackage[font=footnotesize,labelfont=bf]{subcaption}
\begin{document}
\begin{figure}
\begin{subfigure}{0.48\textwidth}
\includegraphics[width=\linewidth]{image1.pdf}
\caption{Caption of first subfigure}
\end{subfigure}
\hspace*{\fill}% this is optional just to fix the horizontal space between the two images
\begin{subfigure}{0.48\textwidth}
\includegraphics[width=\linewidth]{image2.pdf}
\caption{Caption of second subfigure}
\end{subfigure}
\caption{The figures to be shown} \label{A1E}
\end{figure}
\end{document}
`