我正在尝试在上下文 TABLE 环境中制作类似 excel 数据栏的东西。我已经创建了覆盖层,应该可以绘制数据栏,但我不知道如何将数据传递到该覆盖层中。
有可能做类似的事情吗
\defineoverlay[demo circle #1][\useMPgraphic{demo circle}{color=#1}]
??? 或者还有其他方法吗,如何通过 Metapost 绘制 TBALE (\bTD) 的单元格背景并传递数据,以便 \MPvar 访问?
最小工作示例:
\mainlanguage[cz]
\setuppapersize[A4][A4]
\setuplayout[topspace=2cm,backspace=2cm,width=middle,height=middle,header=0.6cm,footer=0.7cm,footerdistance=0.2cm,headerdistance=0.2cm]
\setupcolors[state=start]
\startuseMPgraphic{demo circle}
path p ;
p := fullcircle xscaled \overlaywidth yscaled \overlayheight ;
fill p withcolor .85white ;
draw p withpen pencircle scaled 2pt withcolor \MPvar{color} ;
\stopuseMPgraphic
\defineoverlay[demo circle #1][\useMPgraphic{demo circle}{color=#1}]
\starttext
\placetable{Test}{\bTABLE
\bTR \bTD[background=demo circle blue] aaaaa \eTD \bTD[background=demo circle red] bbbbb \eTD \eTR
\bTR \bTD[background=demo circle green] cccccc \eTD \bTD[background=demo circle black] dddddd \eTD \eTR
\eTABLE}
\stoptext
答案1
将颜色选项传递给框架的标准方法是使用键framecolor
。可以使用访问该键的值 \overlaylinecolor
。例如:
\setupcolors[state=start]
\startuseMPgraphic{demo circle}
newpath p ;
p := fullcircle xscaled \overlaywidth yscaled \overlayheight ;
fill p withcolor .85white ;
draw p withpen pencircle scaled 2pt withcolor \MPcolor{\overlaylinecolor} ;
\stopuseMPgraphic
\defineoverlay[demo circle][\useMPgraphic{demo circle}]
\starttext
\placetable{Test}
{\bTABLE
\bTR
\bTD[background=demo circle, framecolor=red]
aaaaa
\eTD
\bTD[background=demo circle, framecolor=red]
bbbbb
\eTD
\eTR
\bTR
\bTD[background=demo circle, framecolor=green]
cccccc
\eTD
\bTD[background=demo circle, framecolor=green]
dddddd
\eTD
\eTR
\eTABLE}
\stoptext
这使
您可以使用frame=off
来避免默认框架。