上下文:框架問題

上下文:框架問題

我試著用 ConTeXt 定義奇特的框架,但遇到一些困難。由於我發現了很多這樣的例子,所以我主要使用 Metapost,但由於我更擅長 TiKz,所以我不太明白發生了什麼。

首先,我嘗試使用框架文字環境,但在嵌入圖形時(這是我經常需要的),它表現不佳。這就是我想要的框架。

\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

在此輸入影像描述

然後我嘗試使用文字背景;我更改了覆蓋和框架文字定義

\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

但它的表現不佳,而且它似乎不允許可變的線條粗細(而且我找不到有關 multipars 數組的任何文檔...)

在此輸入影像描述

答案1

我建議使用textbackground,因為這可能會跨頁。因此我改編了沃夫岡的解決方案在 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

在此輸入影像描述

相關內容