[Tex/LaTex] Floating TikZ picture within text in mdframed

floatsmdframedtikz-pgfwrapfigure

When there is not enough space for TikZ picture at the end of a text, it will goes to the next page, and leaves an empty space after the text. Is there a standard method for putting TikZ picture in the middle of text, flowing the text to the next page, instead of pushing TikZ picture?

A possible method is using wrapfig page, to put TikZ picture inside wrapfigure. This is a flexible method for floating smaller (e.g. half-sized) TikZ picture within text. I am curious if there is a simpler method for arranging full-width TikZ picture within text to avoid any gap throughout the text.

Here is a very simple example:

\documentclass{article}
\usepackage{mdframed}
\usepackage{lipsum}
\usepackage{tikz}

\begin{document}
\begin{mdframed}
    \lipsum[1-2]
\begin{tikzpicture}
   \draw[fill=blue] (0,0) rectangle (11,11);
\end{tikzpicture}
\end{mdframed}
\end{document}

Since the TikZ picture does not fit in the first page, it will goes to the second page and leave an empty space at the bottom of first page. I want to keep the TikZ picture in the first page, and push the excess text to the second page.

In a long text with several TikZ pictures, I want to avoid any gap within the text.

Best Answer

The package mdframed also tcolorbox use internal saveboxes. Inside such TeX-construction you can't use any floating material. So you have to adjust manual or avoid such an environment.