我正在尝试使用 MetaFun 重现类似的事情:
\definecolor[darkblue][r=20,g=30,b=50]
\startuseMPgraphic{MPTheoremFrame}
% Useful values
numeric w, h, o, b ;
w := OverlayWidth ; h := OverlayHeight ; o := BodyFontSize ;
b := 1pt ; % border size
path theorembox ;% contentbox ;
% LABEL
picture theorem ;
%% Get label and counter
theorem := textext.rt("~\bf\ss\currentconstructionsample~\getnumber[\currentconstruction]~") ;
%% Shift it to the right place
theorem := theorem shifted (o-b/2,h+3(o-b)/2) ;
% THEOREMBOX
%% Set theorembox as a boundingbox around title
theorembox := boundingbox theorem enlarged o;
%% Set theorembox background color
fill theorembox withcolor darkblue ;
%% Draw label/counter with the right color inside theorembox
draw theorem withcolor white ;
% THEOREMTITLE
picture title;
%% Get theorem title
title := textext.rt("~\bf\ss\currentconstructiontitle~") ;
% Shift theorem title next to theorembox
title := title shifted (bbwidth(theorembox), h+3(o-b)/2);
% Draw theorem title
draw title withcolor darkblue ;
% CONTENT
drawoptions (withpen pencircle scaled b withcolor darkblue) ;
draw (0,h)--(0,h)--(0,0)--(w,0)--(w,h)--(xpart urcorner theorembox, h) ;
setbounds currentpicture to OverlayBox ;
\stopuseMPgraphic
\defineoverlay[MPTheoremFrame][\useMPgraphic{MPTheoremFrame}]
\defineframedtext[TheoremFramedText][frame=off,
background=MPTheoremFrame,
offset=\bodyfontsize,
width=\textwidth]
\defineenumeration[theorem][title=yes,
text={\labeltext{theorem}},
alternative=empty,
before=\startTheoremFramedText,
after=\stopTheoremFramedText,
prefix=yes,
way=bysection,
prefixsegments={chapter:section}]
如您所见,有一些问题我无法解决:
- 框位于部分名称和文本上方:这里有一个名为“测试”的部分,被定理框隐藏
- 盒子一个在另一个之上
- 标签框和内容框出了点小问题……
还:
如何将定理名称放在标题框之外?- 有没有正确的方法来使用这些边距框?
- 我如何编辑内容框?(背景、更改字体等...)
答案1
这是一个完全不同且更简单的方法来获得相同的结果。
该示例只是alternative=top
带有左框架和底部框架的示例,通过将定理包装在框架文本内可以轻松实现。
棘手的部分是花哨的标题。ConTeXt 提供了三个钩子来将命令包装在枚举周围:
numbercommand
,仅适用于数字,titlecommand
,仅适用于标题headcommand
,既适用于编号,也适用于标题。
因此,您需要做的就是将其设置numbercommand
为具有蓝色背景的框架,即可完成。
完整代码如下:
\definecolor[darkblue][b=0.8]
\definemeasure[frameoffset][2ex]
\definemeasure[rulethickness][2pt]
\defineframedtext
[theoremframe]
[
frame=off,
leftframe=on,
bottomframe=on,
framecolor=darkblue,
rulethickness=\measure{rulethickness},
width=broad,
offset=overlay,
loffset=\measure{frameoffset},
boffset=\measure{frameoffset},
toffset=-\measure{rulethickness},
]
\defineframed
[headframed]
[
background=color,
backgroundcolor=darkblue,
foregroundcolor=white,
frame=off,
toffset=1ex,
boffset=1ex,
roffset=1ex,
loffset=\measure{frameoffset},
location=low,
]
\defineenumeration
[theorem]
[
text=Theorem,
% Number
prefix=yes,
prefixsegments={chapter:section},
way=bysection,
numbercommand={\hskip-\measure{frameoffset}\relax\headframed},
% Title
title=yes,
titlecolor=darkblue,
titleleft=,
titleright=,
% Frame
before=\starttheoremframe,
after=\stoptheoremframe,
]
\starttext
\startsection[title=An example theorem]
\starttheorem[title={Pythagorean Theorem}]
Let $V$ be an inner product space. If $(u,v) \in V^2$ are orthogonal to each
other, then
\startformula
\lVert u + v \rVert^2 = \lVert u \rVert^2 + \lVert v \rVert^2.
\stopformula
\stoptheorem
\stopsection
\stoptext
这使