[Tex/LaTex] Importing a .png file into .tex file

errorsgraphsimporttexmaker

I've been trying to input a graph into my .tex file, but it won't work. I've put the .png file in the same folder as the .tex file and a part of my code looks like:

\documentclass[16pt, a4paper]{article}
\begin{document}
      .
      .
      .

\usepackage{graphicx}
 \begin{figure} 

\includegraphics{Gaussfit.png}
  \end{figure}
\end{document}

The error message I'm getting is:

! LaTeX Error: Can be used only in preamble.

How can I fix this problem ?

Best Answer

\documentclass[a4paper]{article} %     / after this
\usepackage{graphicx}            % <--{
\begin{document}                 %     \ before this
\begin{figure} 
  \includegraphics[width=\textwidth]{Gaussfit.png}
\end{figure}
\end{document}
Related Question