1

I am trying to put a graph inside my TeX file it somehow misses its original places and moves somewhere else. What can I do to fix it?

Here is my code:

\documentclass{article}
\usepackage{paralist,pst-func, pst-plot, pst-math, pstricks-add,pgfplots}


\documentclass{article}
\usepackage{paralist,pst-func, pst-plot, pst-math, pstricks-add,pgfplots}

\begin{document}
TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST 
\begin{figure}
\begin{center}
    \advance\leftskip-3cm
    \advance\rightskip-3cm
    \includegraphics[width=300pt]{uniform.eps}
    \caption{Mean Square Error calculated for different number of unlabeled $x$ values each in $300$ trials.} 
    \label{fig:MSE}
\end{center}
\end{figure}
TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST 
\end{document}

The result is: enter image description here

Naji
  • 1,505
  • 2
    You should use \centering in your figure environment instead of \begin{center}...\end{center} - avoids extra whitespace around your figure. Also, the figure does not look like it is taking the whole page? – ach May 02 '13 at 17:56
  • @ach I forgot to correct my question after I changed the topic! I am sorry! Thanks for the centering help though! But now my problem is to put the image to the place it belongs! – Naji May 02 '13 at 18:16
  • Try to use \begin{figure}[h]. – Sigur May 02 '13 at 18:17
  • 1
    You should read How to influence the position of float environments like figure and table in LaTeX? and/or Keeping tables/figures close to where they are mentioned, both of which make this question a duplicate. Give some feedback once you've had a chance to look them over. – Werner May 02 '13 at 18:19
  • If you really want the image exactly where you put it in the source code, you may want to avoid using a figure environment at all, since--as I understand it--the purpose of such environments is to allow LaTeX more flexibility in placing the images. I'm pretty sure the caption command still works outside of figure environments, so you can still add a caption this way. – Charles Staats May 02 '13 at 19:11
  • @Naji You are putting your image in a figure environment. The main point of that environment is that it is a float and specifies to LaTeX that the figure should be moved if needed to get good page breaks. Thus the figure moving is the expected behaviour not a problem. If you do not move large units like figure it is impossible to break the pages without leaving part empty pages. – David Carlisle May 02 '13 at 19:12
  • @Sigur please don't suggest using [h] on its own as that just prevents latex putting the figure at the top of a page or on a float page so makes it likely to go to the end of the document. – David Carlisle May 02 '13 at 19:13
  • Never mind my previous comment about using the caption command outside a float; it does not seem to work like this. – Charles Staats May 02 '13 at 19:22
  • 1
    By the way, why does this have the tikz tag? As far as I can tell, the pgfplots package is loaded but not actually used for anything. – Charles Staats May 02 '13 at 19:25

1 Answers1

1

use

\begin{figure}[!htb]

and it should work

  • Actually it worked for three of my plots but still the last one jumps to the next section in my TeX file! Ridiculous! – Naji May 02 '13 at 18:45
  • 1
    @Naji: then there is not enough space on that page for the float. –  May 02 '13 at 20:05