# how to make sure marginpar and an object (like mdframed) stay on the same page?

I have created an environment. I want some figures and text that are supposed to be beside the examples not float to the previous or the next page.

\newmdtheoremenv[
linecolor=orangelight,
linewidth=2pt,
topline=true,
rightline=true,
leftline=true]{eg}{ {\bf Example}}


For example, I have something like this but there is no guarantee that the figure and the example are on the same page.

\marginpar{Look at the intersection of etc \includegraphics[width=1.7in]{Fig1.pdf}
\captionof{figure}{Graph of $f$}}
\begin{eg}
Let $f$ be a continuous function. ....
\end{eg}

• Sounds like an XY problem. No code makes it hard to say. Do not use \bf in LaTeX. It is over 30 years since it became obsolete and ought not be used. – cfr Aug 22 '17 at 2:47
• Please provide the code for a small document which we can compile to reproduce the problem. In tex.stackexchange.com/questions/365013/…, you provided code. That was good, but it was not at all minimal. Try to produce as small an example as possible, but which still shows the problem. Complete minimal examples are almost always needed. Fragments of code which you've favoured in recent questions (when you've provided any code at all) are generally not useful as examples, although they're great in explanations. – cfr Aug 22 '17 at 2:52
• You don't need to use floating environments like figure and table. Minipages and \captionof will do the trick. The marginnote package does not float, although it does have a tendency to overlap. – John Kormylo Aug 22 '17 at 14:52
• @JohnKormylo The margin is blank on most pages. I want something very easy to use for a 400 page document. So I am not sure how minipages that needs to be set on each page or section, can help me do the same. – David R Aug 23 '17 at 8:23
• – John Kormylo Aug 23 '17 at 12:52