如何设置具有不连续水平线的表格?作为示例,我使用了另一个答案中的表格:
我的表格仍然缺少中断规则。另一件事是“Total”上方的规则。使用当前设置,\setupTABLE[row][9][bottomframe=on]
规则太短。\setupTABLE[row][last][topframe=on]
设置后,规则的粗细从 0.03em 变为 0.08em。如何修复这两个规则?
\startsetups table
\setupTABLE [frame=off, rulethickness=.03em]
% vertical alignment
\setupTABLE [column] [align=lohi]
% column spacing
\setupTABLE [column] [each] [loffset=.5ex, roffset=.5ex]
\setupTABLE [column] [first] [loffset=0mm]
\setupTABLE [column] [last] [roffset=0mm]
% rules
\setupTABLE [row] [first] [topframe=on, rulethickness=.08em]
\setupTABLE [row] [2] [topframe=on]
\setupTABLE [row] [last] [bottomframe=on, rulethickness=.08em]
\setupTABLE [row] [6] [topframe=on]
\setupTABLE [row] [last] [align=middle]
% wrong rule width (too short)
\setupTABLE [row] [9] [bottomframe=on]
% wrong rule thickness (should be .03em, but draws .8em)
%\setupTABLE [row] [last] [topframe=on] % wrong rule thickness
\stopsetups
\starttext
\bTABLE [setups=table]
\bTR\bTH Part \eTH\bTH Problem \eTH\bTH Score \eTH\bTH Sum \eTH\eTR
% first part
\bTR\bTD[nr=4] 1 \eTD\bTD 1a \eTD\bTD 2 \eTD\bTD[nr=4] 7 \eTD\eTR
\bTR \bTD 2b \eTD\bTD 2 \eTD \eTR
\bTR \bTD 3a \eTD\bTD 1 \eTD \eTR
\bTR \bTD 5b \eTD\bTD 2 \eTD \eTR
% second part
\bTR\bTD[nr=4] 2 \eTD\bTD 6a \eTD\bTD 2 \eTD\bTD[nr=4] 7 \eTD\eTR
\bTR \bTD 6b \eTD\bTD 2 \eTD \eTR
\bTR \bTD 7a \eTD\bTD 1 \eTD \eTR
\bTR \bTD 8b \eTD\bTD 2 \eTD \eTR
% total
\bTR\bTD[nc=3] Total \eTD\bTD 14 \eTD\eTR
\eTABLE
\stoptext
答案1
划掉最后一行
当你使用
\setupTABLE [row] [9] [bottomframe=on]
该规则只在中间单元格中延伸,因为内部第一个和最后一个单元格不属于第 9 行。从视觉上讲,您可以使用以下方法获得覆盖整行的规则:
\setupTABLE [row] [9] [bottomframe=on]
\setupTABLE [first,last] [6] [bottomframe=on]
现在,当你使用
\setupTABLE [row] [last] [topframe=on]
你得到 0.08em 的规则,因为之前你有
\setupTABLE [row] [last] [bottomframe=on, rulethickness=.08em]
因此规则厚度设置为 0.08em。获取不同厚度的顶部和底部规则的唯一方法是使用 metapost ( background=....
),或使用自定义框架渲染。我展示的是后者,因为我假设您已经知道如何使用自定义背景。
\unprotect
\startuniqueMPgraphic {top_frame}
draw topboundary OverlayBox
withpen pensquare scaled (\the\dimexpr\framedparameter{\c!top\c!rulethickness}\relax)
withcolor \MPcolor{\framedparameter{\c!top\c!framecolor}} ;
setbounds currentpicture to OverlayBox ;
\stopuniqueMPgraphic
% Typo in pack-fen.mkiv
\let\setinstalledframedimensions\pack_framed_overlay_initialize_indeed
\installtopframerenderer{custom}{\uniqueMPgraphic{top_frame}}
\setupframed
[
\c!top\c!rulethickness=\framedparameter\c!rulethickness,
\c!top\c!framecolor=\framedparameter\c!framecolor,
]
\protect
然后使用
\setupTABLE [row] [last] [topframe=custom, toprulethickness=0.03em]
您还可以为左、右和底部框架定义类似的自定义框架。
不连续规则
您还可以定义自定义围栏以具有较短的顶部边框:
\startuniqueMPgraphic {tight_top_frame}
draw (2*\the\dimexpr\framedparameter\c!loffset,OverlayHeight) -- (OverlayWidth - 2*\the\dimexpr\framedparameter\c!roffset, OverlayHeight)
withpen pensquare scaled \overlaylinewidth
withcolor \MPcolor{\overlaylinecolor} ;
setbounds currentpicture to OverlayBox ;
\stopuniqueMPgraphic
\installtopframerenderer{tight}{\uniqueMPgraphic{tight_top_frame}}
(我不确定为什么我需要将loffset
和roffset
乘以 2。)然后使用
\setupTABLE [row] [2] [topframe=tight]
综合以上所有,我们得到:
\unprotect
\startuniqueMPgraphic {top_frame}
draw topboundary OverlayBox
withpen pensquare scaled (\the\dimexpr\framedparameter{\c!top\c!rulethickness}\relax)
withcolor \MPcolor{\framedparameter{\c!top\c!framecolor}} ;
setbounds currentpicture to OverlayBox ;
\stopuniqueMPgraphic
\startuniqueMPgraphic {tight_top_frame}
draw (2*\the\dimexpr\framedparameter\c!loffset,OverlayHeight) -- (OverlayWidth - 2*\the\dimexpr\framedparameter\c!roffset, OverlayHeight)
withpen pensquare scaled \overlaylinewidth
withcolor \MPcolor{\overlaylinecolor} ;
setbounds currentpicture to OverlayBox ;
\stopuniqueMPgraphic
% Typo in pack-fen.mkiv
\let\setinstalledframedimensions\pack_framed_overlay_initialize_indeed
\installtopframerenderer{custom}{\uniqueMPgraphic{top_frame}}
\installtopframerenderer{tight}{\uniqueMPgraphic{tight_top_frame}}
\setupframed
[
\c!top\c!rulethickness=\framedparameter\c!rulethickness,
\c!top\c!framecolor=\framedparameter\c!framecolor,
]
\protect
使用表格设置:
\startsetups table
\setupTABLE [frame=off, rulethickness=.03em]
% vertical alignment
\setupTABLE [column] [align=lohi]
% column spacing
\setupTABLE [column] [each] [loffset=.5ex, roffset=.5ex]
\setupTABLE [column] [first] [loffset=0mm]
\setupTABLE [column] [last] [roffset=0mm]
% rules
\setupTABLE [row] [first] [topframe=on, rulethickness=.08em]
\setupTABLE [row] [2] [topframe=tight]
\setupTABLE [row] [last] [bottomframe=on, rulethickness=.08em]
\setupTABLE [row] [6] [topframe=on]
\setupTABLE [row] [last] [align=middle]
\setupTABLE [row] [last] [topframe=custom, toprulethickness=0.03em]
\stopsetups
这使: