将浮动元素放入阴影框中

将浮动元素放入阴影框中

我创建了一个浮动环境,如下所示

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

我想将示例包含在阴影框中,包括其标题和编号,并提供彩色背景。示例如下。

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

有任何想法吗

答案1

你可以这样使用解决方案Wener 指出。此外,您还需要使用和安装新版本mdframed如解释的那样这里

\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}

色调

相关内容