ConTeXt:添加两行页面边框

ConTeXt:添加两行页面边框

最近我尝试在 ConTeXt 中为文档添加一个简单的双页边框(使用 mtx-context 版本:2023.09.26 18:19)。例如,更正式的封面或文档可能会使用类似的东西。

在此处输入图片描述

如果使用 LaTeX,我会使用eso-pic或只是添加一个tikzpicture矩形。现在使用 ConTeXt。如果使用单线,我会使用\framed如下图所示的https://wiki.contextgarden.net/Framed。但是现在给定一个偏移量和两条要绘制的线。我开始在 MetaPost 中绘制矩形,\startuseMPgraphic使用unitsquare并移动它们。

在 ConTeXt 中还有其他(可能更简单)的选项可以做到这一点吗?

我的最小例子:

\mainlanguage[de]
\language[de]
\enableregime[utf]

\setuppapersize[A4][A4]
\setuplayout[topspace=24mm,
    backspace=24mm,
    header=0pt,
    footer=0pt,
    height=middle,
    width=middle]

\setuppagenumbering[location=]
\setupbodyfont [12pt]

\startuseMPgraphic{pagebackground}
StartPage ;
path outerPath, innerPath;
numeric offset, margin, w, h;
offset := 10mm;
margin := 1mm;
w := OverlayWidth;
h := OverlayHeight;

outerPath := unitsquare xysized (w - 2*offset, h - 2*offset);
outerPath := outerPath shifted (offset, offset);
innerPath := unitsquare xysized (w - 2*offset - 2*margin, h - 2*offset - 2*margin);
innerPath := innerPath shifted (offset + margin, offset + margin);

draw outerPath withpen pencircle scaled 2pt withcolor red;
draw innerPath withpen pencircle scaled 1pt withcolor red;
StopPage ;
\stopuseMPgraphic

\defineoverlay
[pagebackground]
[\useMPgraphic{pagebackground}]

\setupbackgrounds
[page]
[background=pagebackground]

\starttext
\setupinterlinespace[medium]
\hfill
\blank[big]
\startalignment[middle]
{\tfc\bfb Acme Award}\crlf
{\it Founded 1970}\crlf
\blank[big]
\stopalignment
\input tufte
\stoptext

答案1

您可以将背景应用到文本区域并使用OverlayBox具有文本块大小的背景,并enlarged设置边框的偏移量。

\startuseMPgraphic{pageborder}
  draw OverlayBox enlarged 10mm withpen pencircle scaled 1pt withcolor "red";
  draw OverlayBox enlarged 11mm withpen pencircle scaled 2pt withcolor "red";
\stopuseMPgraphic

\defineoverlay
  [pageborder]
  [\useMPgraphic{pageborder}]

\setupbackgrounds
  [text]
  [text]
  [background=pageborder]

\setuplayout
  [tight]
  [   topspace=24mm,
    backspace=24mm,
      cutspace=24mm,
  bottomspace=24mm]

\setuplayout
  [tight]

\setupinterlinespace
  [medium]

\starttext

\blank[force,big]

\startalignment[middle]
  {\bfb Acme Award}\crlf
  {\it Founded 1970}
\stopalignment

\blank[2*big]

\input tufte

\stoptext

相关内容