How can I make a graphic appear underneath the \subsection it is inserted under? [duplicate]

Possible Duplicate:
Keeping tables/figures close to where they are mentioned

I have a .tex document which generates a several paged .pdf document. I have inserted several images of charts / graphs into the document like this:

\section*{section header}

\subsection*{sub section header}
\begin{figure}[htbp]
\centering
\includegraphics{C:/Documents/Samples/image 1.png}
\caption{A caption}
\label{fig:reference}
\end{figure}


What this produces in my multi-paged document is that the image appears on its own page and the section header and sub section header appear after the image despite being inserted before the image in the .tex document.

When I test this out as in a sample document:

\documentclass{article}
\usepackage{graphicx}
\usepackage{grffile}
\begin{document}
\section*{section header}
\subsection*{subsection header}

\subsubsection*{(i)}

\begin{figure}[htbp]
\centering
\includegraphics{C:/Documents/Samples/image 1.png}
\caption{A caption}
\label{fig:reference}
\end{figure}
\end{document}


I do not get this problem. It only seems to occur in my multi-paged document when the image is inserted either side of pages that would otherwise be filled with text.

The images have been inserted using the Insert > Picture option in TeXnicCenter toolbar.

Is there a way to make the graphic appear after the relevant section and subsection and not on its own page before the section and subsection?

-

marked as duplicate by Marco Daniel, lockstep, egreg, Gonzalo Medina, CaramdirSep 25 '11 at 19:57

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

1 Answer

The {figure} environment is floating, which means that TeX looks for the best possible placement in a typographical sense. So if you don’t want your image to float don’˝ put it in a float environment.

Use a {minipage} instead of {figure} and \captionof{figure}{<your caption text>} form the caption package.

Please see the linked/related questions on the right side of you browser window for more informations about floats and their placement ;-)

-
Could you provide a sample? I replaced figure with minipage but it generated several errors in my document. Still getting my head around this LaTeX stuff. Cheers. – Aesir Sep 25 '11 at 13:19
Nevermind, I needed to include the package caption, all works now, thanks! – Aesir Sep 25 '11 at 13:43
@Aesir: Fine that it helps, but consider the linked/related question for other ways (e.g. float option [H] from float package) too … – Tobi Sep 25 '11 at 14:03