使用 ConTeXt 进行排版并使用 metafun 进行绘制,我想为我的目录创建一个自定义彩色覆盖层。我想为某些目录条目填充一个彩色矩形,该矩形从其章节编号(或者更确切地说是我喜欢的数字替代)延伸到页面的右边缘。但是无论我尝试什么,我的带框 metafun 覆盖层始终位于带框元素的中心,我无法不对称地向一侧绘制。
这是一个最小的工作示例。
\setuphead[chapter][number=yes]
\setuphead[section][number=no]
%Draw in TOC
\startuseMPgraphic{TOChighlight}
path p;
p := origin -- origin shifted (0,\overlayheight) -- origin shifted (PaperWidth,\overlayheight) -- origin shifted (PaperWidth,0) --cycle;
fill p withcolor .3red;
\stopuseMPgraphic
\defineoverlay[TOChighlight][\uniqueMPgraphic{TOChighlight}]
\define[1]\ChapterTOCNumber{
\inframed[background=TOChighlight, frame=off]{
\hbox to 3em{\sc \doifnot{\rawstructurelistuservariable{short}}{}{\[\structurelistuservariable{short}\]\crlf} }
}
}
\setuplist[chapter][width=1em, numbercommand=\ChapterTOCNumber, width=5em, alternative=c]
\setuplist[section] [margin=6em]
\starttext
\placecontent[criterium=all]
\startchapter[title=A Vision of The Future][short=What]
\input tufte
\section{What will happen?}
\section{What will cause it?}
\stopchapter
\starttext
\startchapter[title=A Causal Account][short=Why]
\input tufte
\section{Why did it happen?}
\section{Why wasn't it stopped?}
\stopchapter
\stoptext
我尝试的一切都会产生如下结果:
当我尝试实现以下目标时:
额外的加分项:我还想继续沿右边缘绘制颜色,直到下一章(即,不是小节)行。metapost 能否知道下一章行在哪里,即使调用绘制命令时下一章的条目尚不存在?
答案1
我不确定我是否完全明白您想要什么,改变 MetaFun 图片的边界框也许就是您想要的。
我还简化了您的路径 p 并在框架上设置了偏移量。
对于加分题,我不知道。
\setuphead[chapter][number=yes]
\setuphead[section][number=no]
%Draw in TOC
\startuseMPgraphic{TOChighlight}
path p;
p:=unitsquare xyscaled (PaperWidth,OverlayHeight);
fill p withcolor .3red withtransparency (1,.5);
setbounds currentpicture to unitsquare xyscaled (OverlayWidth,OverlayHeight);
\stopuseMPgraphic
\defineoverlay[TOChighlight][\uniqueMPgraphic{TOChighlight}]
\define[1]\ChapterTOCNumber{
\inframed[background=TOChighlight,offset=0pt,frame=off]{
\hbox to 3em{\sc \doifnot{\rawstructurelistuservariable{short}}{}{\[\structurelistuservariable{short}\]\crlf} }
}
}
\setuplist[chapter][width=1em, numbercommand=\ChapterTOCNumber, width=5em, alternative=c]
\setuplist[section] [margin=6em]
\starttext
\placecontent[criterium=all]
\startchapter[title=A Vision of The Future][short=What]
\input tufte
\section{What will happen?}
\section{What will cause it?}
\stopchapter
\starttext
\startchapter[title=A Causal Account][short=Why]
\input tufte
\section{Why did it happen?}
\section{Why wasn't it stopped?}
\stopchapter
\stoptext