1

This is about the 4th or 5th time i have encountered this. Im very new to latex but I'm growing tired of not understanding why this is happening

I place a figure in document with the following code

\begin{figure}[h]
\subfloat{
\includegraphics[width=.7\textwidth]{currentdischarge}
}
\caption{Expected current discharge}
\end{figure}

Then i go and start a new section and continue on with my article

\section{blah blah}

I do a typeset to check my work and every single time my figures are no under my new section instead of where they are suppose to be!

Someone please help! I spend more time fighting latex then i do actually working

Robert
  • 11

1 Answers1

4

use \begin{figure}[!htb] and the figure will be in most cases at the defined position. If you do not want the floating then don't use a float object. Use instead:

\usepackage{capt-of}
...
\begin{minipage}{\textwidth}
\centering
\includegraphics{foo}
\captionof{figure}{bar}\label{baz}
\end{minipage}

With one of the KOMA-Script classes you do not need the package capt-of. Which is, of course, only a oneliner.

  • Ok, can someone get me a bit of code i can use that will work every time to place a picture exactly where I'm coding? The only way i know how to add pictures is with the code i used above – Robert Jul 01 '14 at 21:03
  • 1
    Herbert just did. The "problem" you are facing is called 'floating'. Minipages do not float, so like this you can force them to stay where ever you want. Still, most people here will recommend to let your images float. You should do some reading on this topic in order to see, why this makes sense for typographical reasons. – LaRiFaRi Jul 01 '14 at 21:08
  • @Robert No, your code will not put a picture in the marked place. Moreover, without ! or similar methods sometimes it is completely impossible. – Przemysław Scherwentke Jul 01 '14 at 21:12
  • Thanks for your reply. As I'm sure you can imagine I'm very new to latex and like any language it has a steep learning curve. I found something online that talks about a \Floabarrier. Do you have any information on that? What method is the most accepted in practice? – Robert Jul 01 '14 at 21:14
  • @LaRiFaRi: "If you do not want the floating object ...." –  Jul 01 '14 at 21:21
  • @Robert http://mirrors.ctan.org/macros/latex/contrib/placeins/placeins-doc.pdf (and no, this is not really what you are looking for. But maybe it works if you set a barrier after each float... which makes no sense) – LaRiFaRi Jul 02 '14 at 06:46
  • @Herbert Sorry, I don't follow. Did I write something confusing or did you get me wrong? My first comment was addressed to the OP. – LaRiFaRi Jul 02 '14 at 06:47