[Tex/LaTex] Gray box around figure with a separate gray box around caption

captionsfloatsframed

My university requires that all figures in a thesis follow this pattern:

desired result

I'm very new to LaTeX, so far my best attempt has been this:

\begin{SCfigure}
    \colorbox{darkgray}{
         \begin{minipage}{14cm}
              \centering
              \includegraphics{inductor.jpg}
         \end{minipage}
    }
    \caption{caption caption}
\end{SCfigure}

and the result is here: result so far

My figure is not centered and the caption is off the page.

Trying to create another minipage around caption does not work because the colored box somehow appears in between the figure and caption.

Any help will be highly appreciated. Thank you!

Best Answer

All problems are not resolved. You need to create a macro to automate all the little jobs and I have not used Arial and 8pt. It will be fine to cretae a macro with argument the caption and the picture. I placed a minipage inside a minipage to get margins around the caption. I think there is perhaps a better way to this. I used a box to get the height of the picture, I don't know if it's possible to avoid this.

update 4: I added a macro like Herbert and I adapted the code to odd and even pages but you need to make some calculations to replace \hspace*{-6em} and \hspace*{-4em} by something like \hspace*{\dimexpr -\marginparwidth-\marginparsep\relax} (Herbert's code). I don't know exactly what are the macros for a twoside document to calculate the left and right margin. I corrected 2 bugs. I added some extra space around the picture

\documentclass[11pt]{book} 
\usepackage[utf8]{inputenc} 
\usepackage[T1]{fontenc} 
\usepackage{fourier,xcolor,graphicx} 
\usepackage[font={sf}]{caption} 
 \usepackage{ifthen,changepage,lipsum}

\newsavebox{\mybox}      

\DeclareCaptionLabelSeparator{period-newline}{.\newline\newline}
\captionsetup{aboveskip=3pt,singlelinecheck=false,
              labelsep=period-newline,labelfont={small,bf}} 
\newcommand\Image[4][width=\textwidth]{%
\savebox{\mybox}{\includegraphics[#1]{#2}} 
\fboxsep=0pt 
\checkoddpage  
\ifthenelse{\boolean{oddpage}}{%   
\hspace*{-25mm}  
\hbox{\colorbox{black!10}{\rule{0pt}{\dimexpr \ht\mybox+4mm}%
\begin{minipage}[b]{38mm}\center
 \begin{minipage}[b]{34mm}
   \caption[courte]{#3}
    \label{#4} 
 \end{minipage}%
\end{minipage}}%
\hspace*{2mm}
\colorbox{black!25}{%
\begin{minipage}[b]{145mm}\center
    \vspace*{2mm} 
\colorbox{white}{\usebox\mybox}%
  \vspace*{2mm}  
\end{minipage}}}%     
}{%   
  \hspace*{-40mm}%    
\hbox{\colorbox{black!25}{%
\begin{minipage}[b]{145mm}\center
  \vspace*{2mm}
\colorbox{white}{\usebox\mybox}%
 \vspace*{2mm}  
\end{minipage}}% 
\hspace*{2mm}  
\colorbox{black!10}{\rule{0pt}{\dimexpr \ht\mybox+4mm}%
\begin{minipage}[b]{38mm}\center
 \begin{minipage}[b]{34mm}
   \caption[courte]{#3}
    \label{#4}  
 \end{minipage}%
\end{minipage}}}% 
}   
}
\begin{document} 


\section {Figures/Capturing}

Place Tables/Figures/lmages in text as close to the reterence as possible. (see Figure 1). The table, frgure or image has to put in the area which is width 14.5 cm., filled with 70\% black colm. You should leave 2 mm. tram margin. In a side oox (width 3.8 cm., filled with 15\% Black), a short caption could be in the bottom. 

\begin{figure}[h!]               
 \Image[width=8cm]{elephant.pdf}{Long texte de légende avec quelques explications sur une figure importante}{elephant}  
\end{figure} 

ln tables, pictures, images or captures. use 10pt Arial regular to describe. Each f<gure (group) must include a caption set in 8-points Arial regular. The caption is to be on left or right depends on odd or even page. Figure numbering and referencing should be done sequentially, e.g. Figure. 1, Figure. 2, Table 1., Table 2 .. etc. for single figure and Figure l(a), Figure 1(b)., etc., for figures with multiple parts.    

\lipsum [1]
\section {Figures/Capturing}

\begin{figure}[h!]              
 \Image[width=8cm]{elephant.pdf}{Long texte de légende avec quelques explications sur une figure importante}{elephant bis}  
\end{figure} 
Compare with  the first picture \ref{elephant}
\end{document}  

enter image description here

Related Question