我想要获得一个自定义框架,它与给出的框架不同mdframed
。
这是来自包裹的图片fancytikz海报,它存在于环境minipage
内部tikzpicture
。
这很有效,但由于它在环境中,所以我无法在此框架中创建图形tikzpicture
。
有没有解决方案可以解决这个问题,或者是否有可能在 TikZ 环境之外构建它?
理想情况下,我正在寻找以下形式的东西:
\begin{block}{Block title}
\end{block}
这是生成此帧的代码(图形部分)
%% the content of the block
\draw let \p1=($(#4)-(2.2,0)$),\p2=($(0,\blocktitleheight cm)-(0,0.5cm)$) in
node[draw, anchor=north, color=blocktitlefillcolor, fill=blockfillcolor,
text=blocktextcolor, framefour, rectangle]
(box) at #1 {
\begin{minipage}{\x1}
\vspace{\y2}
\color{blocktextcolor}
#3
\end{minipage}};
%% the title of the block
\begin{scope}
\clip[rounded corners=20] ($(box.south west)+(0.01,0.01)$) rectangle
($(box.north east)-(0.01,0.01)$);
\draw let \p1=($(#4)-(3.2,0)$),\p2=($(0,\blocktitleheight cm)-(0,0.4cm)$)%
in node[anchor=bottom right corner, draw=none, %
bottom color=blocktitlefillcolor, top color=blocktitlefillcolor!85!,
text=blocktitletextcolor, rounded corners=20, inner xsep=1cm, %
minimum height=\y2, minimum width=\x1, %
shape=trapezium, shape border rotate=180, trapezium stretches=true]
(boxtitle) at ($(box.north west)+(1.5,0)$) {\bf\LARGE #2}
%% fading on top
[preaction={path fading=south,fill=blocktitlefillcolor,opacity=.4},draw=none]
($(boxtitle.bottom right corner) - (3,\y2)$) rectangle
($(boxtitle.bottom left corner)+(3,0)$);
\end{scope}
%% decorative drawing on the title
\begin{scope}[even odd rule]
\clip[rounded corners=20] ($(boxtitle.bottom right corner)-(-0.2,0.2)$) --
($(boxtitle.bottom left corner) -(0.2,0.2)$) -- (boxtitle.top left corner)
-- (boxtitle.top right corner) -- cycle %
(box.south west) rectangle (box.north east) ;
\draw[draw=none, rounded corners=20, %
bottom color=blocktitlefillcolor, top color=blocktitlefillcolor!85!]
($(boxtitle.bottom right corner)-(0.5,0)$) --
(boxtitle.bottom right corner) -- (boxtitle.top right corner) --
($(boxtitle.bottom right corner)+(3,0)$) --
($(boxtitle.bottom right corner)-(0.5,0)$)
($(boxtitle.bottom left corner)+(0.5,0)$) --
(boxtitle.bottom left corner) -- (boxtitle.top left corner) --
($(boxtitle.bottom left corner)-(3,0)$) --
($(boxtitle.bottom left corner)+(0.5,0)$) ;
\end{scope}
}
答案1
这是一种使用的可能性tcolorbox
:
\documentclass{article}
\usepackage[svgnames]{xcolor}
\usepackage{tikz}
\usetikzlibrary{shadows,calc}
\usepackage{tcolorbox}
\tcbuselibrary{skins,theorems,breakable}
\usepackage{lipsum}
\definecolor{myblue}{RGB}{40,96,139}
\tcbset{
mybox/.style={
breakable,
enhanced standard,
boxrule=0.4pt,titlerule=-0.2pt,drop fuzzy shadow,
width=\linewidth,
title style={top color=myblue!30,bottom color=myblue!0.5},
overlay unbroken and first={
\path[fill=myblue]
([xshift=5pt,yshift=-\pgflinewidth]frame.north west) to[out=0,in=180] ([xshift=20pt,yshift=-5pt]title.south west) -- ([xshift=-20pt,yshift=-5pt]title.south east) to[out=0,in=180] ([xshift=-5pt,yshift=-\pgflinewidth]frame.north east) -- cycle;
},
fonttitle=\Large\bfseries\sffamily,
fontupper=\sffamily,
fontlower=\sffamily,
before=\par\medskip\noindent,
after=\par\medskip,
center title,
toptitle=3pt,
top=11pt,topsep at break=-5pt,
colback=white
}}
\newtcolorbox{MyBlock}[2][\linewidth]{mybox,width=#1,title=#2}
\begin{document}
\begin{MyBlock}{Some Variable Width Block}
\lipsum[4]
\end{MyBlock}
\begin{MyBlock}[.5\linewidth]{Some Title}
\lipsum[4]
\end{MyBlock}
\end{document}
环境MyBlock
有一个用于标题的强制参数,以及一个用于宽度的可选参数(默认 width= \linewidth
)。
这是相同环境的想法,但这次使用mdframed
包(目前的形式,只允许标题不超过一行):
\documentclass{article}
\usepackage[latin]{babel}
\usepackage[svgnames]{xcolor}
\usepackage[framemethod=tikz]{mdframed}
\usepackage{tikz}
\usetikzlibrary{shadows,calc}
\usepackage{lipsum}
\definecolor{myblue}{RGB}{40,96,139}
\makeatletter
\newenvironment{MiBlock}[2][\linewidth]
{\begin{mdframed}[
skipabove=\topsep,
skipbelow=\topsep,
roundcorner=5pt,
shadow=true,
shadowsize=4pt,
frametitle=\phantom{#2},
frametitlebelowskip=15pt,
font=\sffamily,
innerleftmargin=12pt,
innerrightmargin=12pt,
frametitlefont=\Large\sffamily\bfseries\color{white},
singleextra={
\path[top color=myblue!30,bottom color=myblue!0.5,rounded corners]
([xshift=\pgflinewidth,yshift=-\pgflinewidth]O|-P) rectangle
([xshift=-\pgflinewidth,yshift=-20pt]P) -- cycle;
\path[fill=myblue]
([xshift=5pt,yshift=-\pgflinewidth]O|-P.north west) to[out=0,in=180]
([xshift=20pt,yshift=-25pt]O|-P.north west) --
([xshift=-20pt,yshift=-25pt]P.south east) to[out=0,in=180]
([xshift=-5pt,yshift=-\pgflinewidth]P.north east) -- cycle;
\path let \p1=(P), \p2= (O) in
node at ([yshift=-12pt]0.5*\x1+0.5*\x2,\y1) {\parbox{\dimexpr\mdf@userdefinedwidth@length-40pt\relax
}{\centering\mdf@frametitlefont#2}};
},
userdefinedwidth=#1]}
{\end{mdframed}}
\makeatother
\begin{document}
\begin{MiBlock}{Some Variable Width Block}
\lipsum[2]
\end{MiBlock}
\begin{MiBlock}[0.5\linewidth]{Some Title}
\lipsum[2]
\end{MiBlock}
\end{document}