I knew that floats float around and sometimes are placed far away from where one wants them to be. With the times I learned to work with it, and there are already many posts about it.
I have a kind of different problem. I'm writing my bachelor thesis and defined some environments for definitions and such. And of course I'm using floats as well. But now I have the problem that one of my floats are placed in one of my definitions. This is of course something I really don't want to have. If some of the floats are one page after or before they are referenced, that is ok, but having them in my definitions is no option.
I don't know how to create a MWE for this without posting my whole thesis, but this is as close as I can get:
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[english]{babel}
\usepackage{blindtext}
\usepackage{graphicx}
\newenvironment{myblock}{%
\vspace{.5\baselineskip}
\hrule\nopagebreak\vspace{.35\baselineskip}\nopagebreak}
{\nopagebreak\vspace{.5\baselineskip}\nopagebreak\hrule\vspace{.5 \baselineskip}\noindent}
\newcounter{definition}[section]
\renewcommand*\thedefinition{\thesection.\arabic{definition}}
\newenvironment{definition}{%
\refstepcounter{definition}
\begin{myblock}
\noindent\textbf{Definition \thedefinition}
}
{\end{myblock}}
\begin{document}
\Blindtext
\section{MWE}
\begin{definition}
\blindtext
\end{definition}
\begin{figure}
\includegraphics[scale=.5]{lorem}
\end{figure}
\Blindtext
\end{document}
This is the picture I used for this example.

Well in this example the picture isn't placed that bad, but in my thesis it is placed inside the definition environment.
So my real question is, how can I keep the figure out of that environemnt?
PS: If you see any problems with my definition environment that is not related to this question, please let me know. I'm always happy to learn something new.
\begin{figure}. i haven't checked, but\end{definition}might check what follows to figure out what to do next. a blank line (or\par) will make it clear that it should "stand alone". another possibility: your definition has a page break in the middle, and the figure is at the top of the second page. that's harder to deal with. – barbara beeton Jul 08 '14 at 18:04flafterpackage and\FloatBarrierfrom theplaceinspackage. this kind of thing has been asked in a few other questions, but don't worry, it can be hard to find when you're not sure what to search for :) – cmhughes Jul 08 '14 at 18:05definitionusing\newtheorem(the standard one or theorem or amsthm package variants) doing\noindent\textbf{Definition \thedefinition}you get none of the control pf page breaking that normally happens around latex headings and theorem heads, similarly ending the environment with\noindent}is dangerous as it starts a paragraph so does the wrong thing if a blank line or display environment follows the block. – David Carlisle Jul 08 '14 at 18:19[pb]to prevent the figure going at top of page, or simply move it later in the source. – David Carlisle Jul 08 '14 at 18:21figureenvironment after thedefinitionenvironment with placement parameter[hbp]or before thedefinitionenvironment with placement[ht], then adefinitionthat spans a pagebreak should normally not be interupted by thefigure. – Dan Jul 08 '14 at 19:31figureenvironment; if a picture has to stay somewhere and not to float, it won't need a caption. Just use\includegraphics. – egreg Jul 08 '14 at 20:05