问题
以下数字明细清单与文本不对齐:
代码
可以使用抵消命令:
% Itemized bullet list
\definesymbol[StyleBulletSymbolNumeric][{%
\offset[y=0.2\baselineskip]{%
\StyleBulletFramed[
width=1em,
]{\small\small\currentitemnumber}
}
}]
y=0.2\baselineskip
但是,无论是还是的计算y=0.2\lineheight
都没有将数字及其背景与文本完全垂直对齐。
问题
如何垂直对齐列表项的编号,以便:
- 数字在框架内垂直对齐;并且
- 框架是否与分项文本垂直对齐?
想法
我努力了:
location=middle
- 产生的帧太低command=\vcenter
- 没有明显效果\offset[y=0.15\baselineskip]{%
- 最接近:
在上图中,编号项目应该相对于对象高 2px \framed
,而y
的值offset
几乎是完美的(我担心改变字体及其大小会导致对齐偏离;也就是说,这是一个脆弱的计算,应该使用常数而不是 的神奇数字0.15
)。
例子
显示问题的完整示例:
\setupcolors[state=start]
% Defines the frame style for bullets. This replaces the leader dots in the
% ToC as well as provides the starting point for all squares.
\defineframed[StyleBulletFramed][
frame=off,
width=0.5em,
height=\framedparameter{width},
background=color,
backgroundcolor=red,
]
% Defines the bullet as a symbol, which can be used with bullet lists.
\definesymbol[StyleBulletSymbol]
[{\StyleBulletFramed{\strut}}]
% Defines the bullet as a symbol, which can be used with numbered lists.
% Twice small to ensure the number fits inside the bullet.
\definesymbol[StyleBulletSymbolNumeric][{%
\offset[y=0.15\baselineskip]{%
\StyleBulletFramed[
width=1em,
%location=middle,
command=\vcenter
]{\small\small\currentitemnumber}
}
}]
\define[1]\instruction{\startitem #1. \stopitem}
\defineitemgroup[Instructions]
\setupitemgroup[Instructions][each][joinedup]
\setupitemgroup[Instructions][
symbol=StyleBulletSymbolNumeric,
location=middle,
]
\starttext
\startbodymatter
\startInstructions
\instruction{Set up the video camera's tripod at the hallway door}
\instruction{Start the video recorder}
\instruction{Make sure the path to the hallway door is unobstructed}
\instruction{Ensure both laces on your running shoes are tied tight}
\instruction{Check that nobody else is in the room}
\instruction{Don safety goggles}
\instruction{Using metal serving tongs, hold the sodium over the water}
\instruction{Drop the sodium into the water}
\instruction{Run to the hallway}
\instruction{Prepare to call the fire department}
\instruction{Upload video to YouTube}
\stopInstructions
\stopbodymatter
\stoptext
参考
答案1
ConTeXt 已经有一个机制来确保\framed
与文本基线对齐:\framed[location=low]{...}
。但是,当您明确设置框架的高度时,此机制会失效。因此,您需要做的不是设置框架的高度,而是更改背景的高度。例如,
\setupbodyfont[10pt]
\edef\defaultlineheight{\the\lineheight}
\startMPdefinitions
newpath basicShape;
basicShape := unitsquare ;
DefaultLineHeight := \defaultlineheight;
\stopMPdefinitions
\startuseMPgraphic {unnumberedbullet}
fill basicShape scaled OverlayWidth shifted (0, 0.5*LineHeight)
withcolor \MPcolor{red};
setbounds currentpicture to OverlayBox;
\stopuseMPgraphic
\startuseMPgraphic {numberedbullet}
fill basicShape xyscaled (0.9*DefaultLineHeight, 0.9*DefaultLineHeight)
shifted (-0.5(0.9*DefaultLineHeight - OverlayWidth, 0))
withcolor \MPcolor{green};
setbounds currentpicture to OverlayBox;
\stopuseMPgraphic
\defineoverlay[unnumberedbullet][\useMPgraphic{unnumberedbullet}]
\defineframed [unnumberedbullet]
[
frame=off,
width=0.5\bodyfontsize,
background=unnumberedbullet,
location=low,
]
\definesymbol[unnumberedbullet]
[{\unnumberedbullet{}}]
\defineoverlay[numberedbullet][\useMPgraphic{numberedbullet}]
\defineframed [numberedbullet]
[
frame=off,
width=\lineheight,
background=numberedbullet,
% Center the number against capital letters, ignoring character descent
location=depth,
foregroundstyle={\small\small}, % better to define a custom fontswitch
]
\definesymbol[numberedbullet]
[{\numberedbullet{\currentitemnumber}}]
\starttext
\startitemize[unnumberedbullet]
\item One
\item Two
\item Three
\stopitemize
\startitemize[numberedbullet]
\item gpat
\item Two
\item Three
\stopitemize
\stoptext
这使
要更改项目符号的形状,请将其更改basicShape := unitsquare
为任何其他形状。例如,要获得圆形,请使用basicShape := unitcircle
。