Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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 ?

share|improve this question
1  
article class has not got a 16pt option, and \usepackage as it says in the errror message has to be in the preamble ie before \begin{document} so just move that line. –  David Carlisle Feb 3 at 11:19
    
Welcome to TeX.SX! You can have a look at our starter guide to familiarize yourself further with our format. As David said, put the \usepackage{graphicx} in the preamble, which is between the \documentclass and \begin{document}. –  hpesoj626 Feb 3 at 11:21
    
Thanks, it woks. But the graph is too large. How can I define the size of the graph? –  Nikoleta Feb 3 at 11:28
add comment

2 Answers

\documentclass[a4paper]{article}
\usepackage{graphicx}
\begin{document}
\begin{figure} 
  \includegraphics[width=\textwidth]{Gaussfit.png}
\end{figure}
\end{document}
share|improve this answer
add comment

You can also pass an option to set the scale of the image, like so:

\includegraphics[scale=0.5]{Gaussfit.png}

In this case, the image will be scaled to half size. Also, including the file extension, i.e. .png is not mandatory.

You can check for additional options here.

share|improve this answer
1  
scale might not be a good idea. Better to scale using say width=0.8\textwidth, or use this interesting answer tex.stackexchange.com/q/157337/3929 –  daleif Feb 3 at 15:39
    
Can you explain why wouldn't scale be a good idea? –  Oxfist Feb 3 at 15:44
    
Do you know the original size? So the value for scale will be trail and error, plus what if the margins change? Then you have to go over all of them to make sure they are no longer too wide. –  daleif Feb 3 at 15:48
    
Great explanation, thanks! –  Oxfist Feb 3 at 15:51
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.