答案1
您可以使用该命令创建凸起的规则。当您使用该命令\blackrule
测量文本的宽度时,可以计算出规则的正确宽度。section
\dowithnextbox
\define\SectionTextCommand
{\dowithnextbox
{\beginhbox
\blackrule[width=\dimexpr(\hsize-\nextboxwd-2\emwidth)/2\relax,height=0.8ex,depth=-0.6ex,color=middlecyan]%
\quad
\copy\nextbox
\quad
\blackrule[width=\dimexpr(\hsize-\nextboxwd-2\emwidth)/2\relax,height=0.8ex,depth=-0.6ex,color=middlecyan]%
\endhbox}
\hbox}
\setuphead
[subject]
[textstyle={\setcharactercasing[WORD]\ssa},
textcommand=\SectionTextCommand]
\starttext
\subject{Skills}
\stoptext
另一种方法是使用filler
机制在文本的左侧和右侧放置规则,占用可用空间而无需计算。
\definefiller
[SectionRule]
[alternative=rule,
color=middlecyan,
height=0.8ex,
depth=-0.6ex]
\definefiller
[SectionLeftRule]
[SectionRule]
[left=\zerowidthnobreakspace,
right=\quad]
\definefiller
[SectionRightRule]
[SectionRule]
[left=\quad,
right=\zerowidthnobreakspace]
\setuphead
[subject]
[%align=middle,
textstyle={\setcharactercasing[WORD]\ssa},
textcommand=\groupedcommand{\filler[SectionLeftRule]}{\filler[SectionRightRule]}]
\starttext
\subject{Skills}
\stoptext