我正在尝试使用 ConTeXt 定义花式框架,但遇到了一些困难。由于我发现了许多这样的例子,我主要使用 Metapost,但由于我更擅长 TiKz,所以我不太明白发生了什么。
首先,我尝试使用 framedtext 环境,但在嵌入图形时会出现错误(这是我经常需要的)。这是我想要的框架。
\usesymbols[mvs]
\definesymbol[info][{\symbol[martinvogel 2][Info]}]
\startuseMPgraphic{mp:axiomframe}
draw (OverlayWidth,OverlayHeight) -- (0,OverlayHeight) -- (0,0);
draw (0.5pt,0) -- (OverlayWidth,0) -- (OverlayWidth,OverlayHeight-
0.5pt) withpen pencircle scaled 1.2bp;
fill OverlayBox withcolor 0.95 white;
fill bbox textext.top("\tfd\symbol[info]") shifted
(0.5EmWidth,OverlayHeight-3ExHeight) withcolor white;
draw textext.top("\tfd\symbol[info]") shifted
(0.5EmWidth,OverlayHeight-3ExHeight) ;
setbounds currentpicture to OverlayBox ;
\stopuseMPgraphic
\defineoverlay[axiomframe][\useMPgraphic{mp:axiomframe}]
\defineframedtext[theoremFrame]
[frame=off,
rulethickness=1pt,
offset=5pt,
background=axiomframe,
width=fit,
location=middle]
\def\starttheorem{\dosingleempty\doStarttheorem}
\def\doStarttheorem[#1]{
\starttheoremFrame
\iffirstargument \hskip2em {\bfa #1} \\ \fi
}
\def\stoptheorem{\stoptheoremFrame}
\useexternalfigure[ctanlion]
[http://www.ctan.org/lion/ctan_lion_350x350.png][width=5cm]
\starttext
\starttheorem[Hello]
\placefigure[here,right,none]{}{\externalfigure[ctanlion]}
\input knuth
\stoptheorem
然后我尝试使用 textbackground ;我使用以下方法更改了 overlay 和 framedtext 定义:
\definetextbackground[theoremFrame]
[mp=mp:axiomframe,
leftoffset=2\bodyfontsize,rightoffset=.5\bodyfontsize,
topoffset=.5\bodyfontsize,bottomoffset=.5\bodyfontsize,
before={\testpage[3]\blank},
after={\blank[2*medium]},
width=local]
这解决了浮动问题,但导致了以下问题:框架占据了整个页面而不是所需的空间,而且我无法设法在边缘上获得空间:
最后,我尝试使用 Aditya 的文档修改 MP 部分:
\startuseMPgraphic{mp:axiomframe}
path p;
for i = 1 upto nofmultipars :
p = (multipars[i] topenlarged 0pt bottomenlarged 0pt);
fill p withcolor 0.95white ;
draw p withcolor black withpen pencircle scaled
\MPvar{linewidth};
endfor;
fill bbox textext.top("\tfd\symbol[info]") shifted
(0.5EmWidth,OverlayHeight-3ExHeight) withcolor white;
draw textext.top("\tfd\symbol[info]") shifted
(0.5EmWidth,OverlayHeight-3ExHeight) ;
setbounds currentpicture to OverlayBox ;
\stopuseMPgraphic
但它的表现并不好,并且它似乎不允许可变的线条粗细(并且我找不到有关多部分数组的任何文档......)
答案1
我建议使用textbackground
,因为这可能会跨页面中断。因此我改编了 Wolfgang 的解决方案在 ConTeXt 中构建整个部分。
\usesymbols[mvs]
\definesymbol[info][{\symbol[martinvogel 2][Info]}]
\startuseMPgraphic{mp:axiomframe}
begingroup;
for i=1 upto nofmultipars :
% Draw the surrounding box
path p;
p := ( llcorner multipars[i]
-- lrcorner multipars[i]
-- urcorner multipars[i]
-- ulcorner multipars[i]
-- cycle )
enlarged (EmWidth,EmWidth) ;
fill p withcolor boxfillcolor ;
draw p withcolor boxlinecolor ;
draw (p cutbefore point 2 of p cutafter point 4 of p)
withpen pencircle scaled 2pt
withcolor boxlinecolor ;
% Draw the info symbol
picture pic;
pic := textext.ulft("\tfd\symbol[info]");
pic := pic shifted ulcorner multipars[i];
fill bbox pic withcolor white;
draw pic;
endfor ;
setbounds currentpicture to OverlayBox ;
endgroup;
\stopuseMPgraphic
\definetextbackground
[theoremFrame]
[mp=mp:axiomframe,
location=paragraph,
backgroundcolor=green,
framecolor=red,
before={\testpage[3]\blank},
after={\blank[2*medium]}]
\defineenumeration
[theorem]
[text=,
number=no,
title=yes,
titledistance=2em,
titleleft=,
titleright=,
before={\starttextbackground[theoremFrame]},
after={\stoptextbackground}]
\useexternalfigure[ctanlion]
[http://www.ctan.org/lion/ctan_lion_350x350.png][width=5cm]
\starttext
\starttheorem[title=Hello]
\placefigure[here,right,none]{}{\externalfigure[ctanlion]}
\input knuth
\stoptheorem
\input lorem
\starttheorem[title=Hello]
\placefigure[here,right,none]{}{\externalfigure[ctanlion]}
\input knuth
\stoptheorem
\stoptext