# How to force a framed box not to be cut by the end of page

I would like to know how to keep a whole framed box on the same page. I am finishing a manuscript and I am quite afraid to move the text before/after to check this.

I take this example, from here.

\documentclass{article}
\usepackage[framemethod=TikZ]{mdframed}
\usepackage{lipsum}
\mdfdefinestyle{MyFrame}{%
linecolor=blue,
outerlinewidth=2pt,
roundcorner=20pt,
innertopmargin=\baselineskip,
innerbottommargin=\baselineskip,
innerrightmargin=20pt,
innerleftmargin=20pt,
backgroundcolor=gray!50!white}

\begin{document}

\begin{mdframed}[style=MyFrame]
\lipsum[1]
$$f(x) = \sin(x)$$
\lipsum[2]
\end{mdframed}
\end{document}


I know that in the figures, you can put a "H", like this:

\begin{figure}[H]
\centering
\includegraphics[width=0.8\linewidth]{image}
\caption{This is the caption.}
\label{fig:label_image}
\end{figure}


Is it possible to do so with framed box ? And/or fix at the page number 2 ?

Just put in inside a parbox:

\documentclass{article}
\usepackage[framemethod=TikZ]{mdframed}
\usepackage{lipsum}
\mdfdefinestyle{MyFrame}{%
linecolor=blue,
outerlinewidth=2pt,
roundcorner=20pt,
innertopmargin=\baselineskip,
innerbottommargin=\baselineskip,
innerrightmargin=20pt,
innerleftmargin=20pt,
backgroundcolor=gray!50!white}

\begin{document}
\lipsum[1-3]
$$f(x) = \sin(x)$$

• It doesn't work for me... lot of message error ! What is \textwidth ? @koleygr – Agape Gal'lo Oct 23 '18 at 17:11
• Sorry ! I missed the final "}". Your code works perfectly ! – Agape Gal'lo Oct 23 '18 at 18:03