Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I have created a float enivoirment as shown below

\floatstyle{boxed}
\newfloat{example}{thp}{lop}[section]
\floatname{example}{Example}

I would like to enclose the example in the a shadowbox, including its caption and numbering and also provide a coloured background. Example is provided below.

----------------------------------------------
| Example 2.3: How to define an attribute    |
|                                            | 
| def ..etc                                  |
|                                            |
----------------------------------------------

Any ideas

share|improve this question
1  
Perhaps the post on Rounded corner colored box around figure might be a good start. –  Werner Feb 6 '12 at 6:33

1 Answer 1

up vote 6 down vote accepted

This is how you can use the solution that Wener points out. Also, you will need to use and install the new version of the mdframed as explained here.

\documentclass{article}
\usepackage{float}
\usepackage[framemethod=tikz]{mdframed}
\usetikzlibrary{shadows}% needed for the shadows

% Styles
\mdfdefinestyle{shadowBox}{backgroundcolor=yellow!10,shadow=true, roundcorner=25pt,tikzsetting={draw=yellow!80!black!30, line width=1pt}}%

\mdfdefinestyle{blueBox}{backgroundcolor=blue!10,shadow=true, shadowcolor=blue!10, roundcorner=25pt,tikzsetting={draw=blue!80!black!30, line width=1pt}}%

\makeatletter
  % General command that defines the mdframed
  \newcommand\shadowFloat[1]{\def\@fs@cfont{\bfseries}\let\@fs@capt\floatc@plain
  \def\@fs@pre{\begin{mdframed}[style=#1]}%
  \def\@fs@mid{}%
  \def\@fs@post{\end{mdframed}}\let\@fs@iftopcapt\iffalse}
  % Link the style with the frame, giving it a name
  \newcommand\fs@yellowFloat{\shadowFloat{shadowBox}}
  \newcommand\fs@blueFloat{\shadowFloat{blueBox}}
\makeatother

\pagestyle{empty}
\begin{document}

\floatstyle{yellowFloat}
\restylefloat{figure}% bind the style to the figure
\begin{figure}[h]
    \centering
    \rule{100pt}{150pt}
    \caption{Some caption}
\end{figure}

\floatstyle{blueFloat}
\restylefloat{figure}% bind the style to the figure
\begin{figure}[h]
    \centering
    \rule{100pt}{150pt}
    \caption{Another caption}
\end{figure}
\end{document}

shades

share|improve this answer
    
Perfect! Is it possible to have different styles for different floats. In my book, i have floats of different type, 'Examples', 'Logs', 'code snippets', etc –  user739807 Feb 6 '12 at 12:17
    
Yes you can, see my update. –  adn Feb 6 '12 at 12:59
    
Thanks! One more (last one) question, the frames seem to go beyond my page margins, any way to fix this! –  user739807 Feb 6 '12 at 13:32
    
@user739807: Really? Only the shadows run into the margin. I explained that in the documentation. –  Marco Daniel Feb 6 '12 at 14:05
    
@MarcoDaniel, I removed the shadows to test, Still the frames go beyond the margin. I wanted to attach an example (an image) here, but i cant find instructions on how to do so! –  user739807 Feb 7 '12 at 10:23

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.