[Tex/LaTex] mdframed box containing text captioned tables and figures

floatsmdframed

I would like to create a framed boxes containing arbitrary text, captioned tables and captioned figures. But mdframed does not allow floats inside. How does one achieve this? Something like this does not work because you cannot insert a float inside mdframed:

\begin{mdframed}
\lipsum[4-6]
\begin{figure}\centering{\includegraphics[width=8cm,height=5cm]{exampleimg}\caption{exampleimg}}\end{figure}
\lipsum[1-3]
\end{mdframed}


\begin{mdframed}
\lipsum[4-6]
\begin{threeparttable}
\caption{\label{milk-consumption-india}Asdkj sdlkj sldkjf lskjd flograms per capita per annum}
\begin{center}
\begin{tabulary}{\textwidth}{lrrr}
Year & Rural & Urban & All\\
\hline
1983 & 38.7 & 55.6 & 44.7\\
1993–1994 & 50.3 & 66.4 & 54.3\\
2004–2005 & 50.2 & 69.3 & 55\\
2009–2010 & 51.7 & 71.6 & 57.1\\
\end{tabulary}
\end{center}
\begin{tablenotes}
\item[] \footnotesize Source: \citet{anjani2014}
\end{tablenotes}
\end{threeparttable}
\lipsum[1-3]
\end{mdframed}

How to insert a table or a figure inside mdframed box without making it float?

Best Answer

After clarifications from the OP through comments, it is better to use \captionof from caption package and get rid of both figure and table environments. For table notes, an extra row may be added as shown.

\documentclass{article}
\usepackage{mdframed,graphicx,caption}
\usepackage{lipsum}

\begin{document}
    \begin{mdframed}
      \lipsum[4]
      {\centering
      \includegraphics[width=3cm,height=3cm]{example-image-a}
      \captionof{figure}{exampleimg}
      \par}
      \lipsum[1]
\lipsum[4-6]
\begin{center}
\captionof{table}{\label{milk-consumption-india}Asdkj sdlkj sldkjf lskjd flograms per capita per annum}
\begin{tabular}{lrrr}
  Year        & Rural & Urban & All   \\ \hline
  1983        & 38.7  & 55.6  & 44.7  \\
  1993–1994   & 50.3  & 66.4  & 54.3  \\
  2004–2005   & 50.2  & 69.3  & 55    \\
  2009–2010   & 51.7  & 71.6  & 57.1  \\
  \multicolumn{4}{@{}l@{}}{\footnotesize Source:} %\citet{anjani2014}}
\end{tabular}
\end{center}

\lipsum[1-3]
\end{mdframed}
\end{document}

enter image description here