# How to draw frame around side captioned figure

I want to draw frame around a side captioned figure. I have created side captioned figure using sidecap package and using \begin{SCfigure} \end{SCfigure} environment. I have tried mdframed package but it is not working. I have also tried \fbox{} but frame is coming around graphicx only not around caption. I have googled a lot but could not find out a suitable answer.
The following example works

\documentclass{report}
\usepackage[demo]{graphicx}
\usepackage{sidecap}
\usepackage{mdframed}
\begin{document}
\begin{figure}
\begin{mdframed}
\centering
\includegraphics{image}
\caption{A figure and its caption framed}
\label{fig:test}
\end{mdframed}
\end{figure}
\begin{SCfigure}
\includegraphics{image}
\caption{A figure and its caption framed}
\label{fig:test}
\end{SCfigure}

\end{document}


But following example doe snot works

\documentclass{report}
\usepackage[demo]{graphicx}
\usepackage{sidecap}
\usepackage{mdframed}
\begin{document}
\begin{figure}
\begin{mdframed}
\centering
\includegraphics{image}
\caption{A figure and its caption framed}
\label{fig:test}
\end{mdframed}
\end{figure}
\begin{SCfigure}
\begin{mdframed}
\includegraphics{image}
\caption{A figure and its caption framed}
\label{fig:test}
\end{mdframed}
\end{SCfigure}

\end{document}


Giving the following error Something's wrong--perhaps a missing \item. \includegraphics

-
Please add a minimal working example (MWE). – mafp May 23 '13 at 13:19
The boxhandler package can add these kind of box "wrappers" around traditional figures, but alas not for sidecap figures. – Steven B. Segletes May 23 '13 at 13:55
Sorry @mafp I have added MWE now. – Apurba May 24 '13 at 14:23
Do you want to draw the frame around Scfigure or around the graphic? – Marco Daniel May 24 '13 at 14:44
@MarcoDaniel I want to draw frame around SCfigure. I can draw frame around normal figure. – Apurba May 24 '13 at 14:49

If you are willing to switch to another package, the powerful floatrow package has a BOXED style for these cases:

\documentclass{article}
\usepackage[demo]{graphicx}
\usepackage{floatrow}

\begin{document}

{
\floatsetup{style=BOXED,capposition=beside,capbesideposition={top,left}}
\begin{figure}
\includegraphics{image}
\caption{A figure and its caption framed}
\label{fig:test}
\end{figure}
}

\end{document}


The demo option for graphicx simply replaces actual figures with black rectangles; do not use that option in your actual document.

-
This is working but problem is it is making all figure in side caption mode. I have only 5 - 6 figure in side caption mode. All other figure should be in traditional figure mode. Is it possible to use floatrow package in this case. – Apurba May 24 '13 at 14:26
@Apurba Sure it's possible, Please see my updated answer. – Gonzalo Medina May 24 '13 at 17:57

The issue is not related to mdframed. It based on an implementation of sidecap As the following example shows:

\setcounter{errorcontextlines}{999}
\documentclass{report}
\usepackage[demo]{graphicx}
\usepackage{sidecap}

\begin{document}
\begin{SCfigure}
\begin{itemize}
\item foo
\end{itemize}
\caption{A figure and its caption framed}
\label{fig:test}
\end{SCfigure}
\end{document}


The issue is that sidecap saves the material inside an hbox. So every vertical material like itemize or list results in an error. To handle such vertical material you have to specify a minipage or a something similar.

To work with mdframed you have to patch the output command of sidecap.

Here an example:

\documentclass{report}
\usepackage[demo]{graphicx}
\usepackage{xcolor}
\usepackage{sidecap}
\usepackage[framemethod=tikz]{mdframed}
\mdfdefinestyle{sidefig}{middlelinewidth=2pt,backgroundcolor=lightgray,roundcorner=8pt}
\usepackage{xpatch}
\makeatletter
\xpatchcmd{\endSC@FLOAT}{\@FLOAT{\SC@captype}}{\@FLOAT{\SC@captype}\begin{mdframed}[style=sidefig]}{}{}
\xpatchcmd{\endSC@FLOAT}{\end@FLOAT}{\end{mdframed}\end@FLOAT}{}{}
\makeatother
\begin{document}
\begin{SCfigure}
\includegraphics{image}
\caption{A figure and its caption framed}
\label{fig:test}
\end{SCfigure}
\end{document}


-
would be nice to have just a little space between figure and caption. (it looks like the "obvious" approach, adding \hspace won't work.) – barbara beeton May 24 '13 at 15:16
@barbarabeeton: Indeed. Needs to patch some more internals ;-) – Marco Daniel May 24 '13 at 15:26
@barbarabeeton: It is an issue with standalone. – Marco Daniel May 24 '13 at 16:34
glad it wasn't something more complicated. – barbara beeton May 24 '13 at 17:33