我是 ConTeXt 的新手,正在尝试为我的演示文稿制作一个小主题,以便更好地了解它。
我的幻灯片在页眉中有一个标题和一个副标题。我想在标题和副标题之间添加随机线条。当直接在标题和副标题之间通过时,线条应该连接并变成水平线。
我删除了文档中不相关的部分。目前有一条线,它在中心附近变平了一段距离瓦. 我正在尝试获取瓦来自 MPpage 外部。
为了澄清一点,这是我目前使用固定值得到的结果(抱歉,那些是截图):
说实话,我甚至不知道从哪里开始解决这个问题。欢迎任何指点。以下是 WE/MWE:
\setuppapersize[S6]
\setuplayout[headerdistance=1cm]
\definemarking[subtitle]
\starttexdefinition slidetitle
\marking [subtitle] {\structureuservariable{subtitle}}
\stoptexdefinition
% Defining the slides
\definehead[slide] [subject][
page=yes,
placehead=empty,
insidesection=\slidetitle,
]
%Putting the slide title and subtile in a table (to get 2 bloody lines) inside the header
\setupheadertexts [{%
\bTABLE[frame=no,align=middle,offset=0.05cm]
\bTR \bTD {\getmarking [slide]} \eTD \eTR
\bTR \bTD {\tfx\getmarking [subtitle]} \eTD \eTR
\eTABLE
}]
\setupheader[text][style=\sc\ss\tfb]
\startuseMPgraphic {background}
StartPage;
%Drawing the top lines. The variable w should be the max of the widths of the title and subtitle. So basically the width of the natural table containing them
numeric w; path line;
w=6cm;
line:=((0,0) -- for i=1cm step 1cm until PaperWidth/2-w/2-1cm : (i,-uniformdeviate(0.7cm)) -- endfor (PaperWidth/2-w/2,-0.5cm) -- (PaperWidth/2+w/2,-0.5cm) -- for i=PaperWidth/2+w/2+1cm step 1cm until PaperWidth-1cm : (i,-uniformdeviate(0.7cm)) -- endfor (PaperWidth,0)) shifted (0,PaperHeight-1.8cm);
drawpath line withpen pencircle scaled 1mm;
StopPage;
\stopuseMPgraphic
\defineoverlay [background][\reuseMPgraphic{background}]
\setupbackgrounds[page][background=background]
\starttext
\startslide[title={Hello}]
\input knuth
\stopslide
\startslide[title={Font examples}] [subtitle=a subtitle]
\input ward
\stopslide
\startslide[title={A very very long and detailed title}]
[subtitle={As well as an inexcusably long and annoying subtitle}]
some text
\stopslide
\stoptext
如果帖子不符合某些规则,请原谅,因为我不习惯在这里发帖。
答案1
sztruks 的回答:
我认为您可以使用位置图形,如 Metafun 手册第 5 章中所定义。
编辑:我使用位置图形得到的结果并不完全正确。我为标题-副标题包分配了一个 \hpos 并获取其宽度。不幸的是,据我所知,\startMPpositiongraphic 仅在整个文档排版完成后才计算,此时 \hpos 仅引用最后一页的标题-副标题。因此,除了最后一页外,其他页面上都没有绘制线条。然而,它们以正确的尺寸绘制。
EDIT2:只需将计数器的值放入 hpos(特别是 \userpagenumber)中,并将 \start/stoppositionoverlay 代码放入在每张幻灯片上执行的某个函数中即可解决(这样计数器就会更新,否则只有第一页会得到绘图)。不发布新图片,因为下面的图片已经描述了我得到的结果。
将问题标记为已回答。
以下是我现在拥有的:
\setuppapersize[S6]
\setuplayout[headerdistance=1cm]
\definemarking[subtitle]
\starttexdefinition slidetitle
\marking [subtitle] {\structureuservariable{subtitle}}
\startpositionoverlay{posover:background}
\setMPpositiongraphic{titles-\userpagenumber}{background}{self=titles-\userpagenumber}
\stoppositionoverlay
\stoptexdefinition
% Defining the slides
\definehead[slide] [subject][
page=yes,
placehead=empty,
insidesection=\slidetitle,
]
%Putting the slide title and subtile in a table (to get 2 bloody lines) inside the header
\setupheadertexts [\hpos{titles-\userpagenumber}{%
\bTABLE[frame=no,align=middle,offset=0.05cm]
\bTR \bTD {\getmarking [slide]} \eTD \eTR
\bTR \bTD {\tfx\getmarking [subtitle]} \eTD \eTR
\eTABLE
}]
\setupheader[text][style=\sc\ss\tfb]
\startMPpositiongraphic {background}
StartPage;
%Drawing the top lines. The variable w should be the max of the widths of the title and subtitle. So basically the width of the natural table containing them
numeric w; path line;
w=\MPw{\MPvar{self}} ;
line:=((0,0) -- for i=1cm step 1cm until PaperWidth/2-w/2-1cm : (i,-uniformdeviate(0.7cm)) -- endfor (PaperWidth/2-w/2,-0.5cm) -- (PaperWidth/2+w/2,-0.5cm) -- for i=PaperWidth/2+w/2+1cm step 1cm until PaperWidth-1cm : (i,-uniformdeviate(0.7cm)) -- endfor (PaperWidth,0)) shifted (0,PaperHeight-1.8cm);
drawpath line withpen pencircle scaled 1mm;
StopPage;
\stopMPpositiongraphic
\defineoverlay [over:background][\positionoverlay{posover:background}]
\setupbackgrounds[page][background=over:background]
\starttext
\startslide[title={Hello}]
\input knuth
\stopslide
\startslide[title={Font examples}] [subtitle=a subtitle]
\input ward
\stopslide
\startslide[title={A very very long and detailed title}]
[subtitle={As well as an inexcusably long and annoying subtitle}]
some text
\stopslide
\stoptext