# mdframed box containing text captioned tables and figures

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?

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}


• How would one do this with a table? I am not able to add caption to a table. The caption takes the width of the table, and does not use the entire \textwidth. I just added the code I am using for inserting the table. – len71 Mar 10 '15 at 7:25
• But my table does not have long content. I can do away of tabulary, if that helps. – len71 Mar 10 '15 at 8:56
• puting mdframed inside \begin{table} and \end{table} creates all kinds of problems for me. pagebreaks stop working. Also, if a box has some text, a captioned table and a captioned figure, all hell breaks loose. – len71 Mar 10 '15 at 12:25
• I have a text running over two and a half pages containing one figure and a table, that I would like to insert as a framed box in a document (manuscript for a book). Both figure and table have a caption. – len71 Mar 10 '15 at 12:56