我已使用 TikZ 图形使用以下代码成功绘制了一个符号(五边形中的数字):
this is a very very very very very very very very very long text before symbol%
\starttikzpicture
% draw pentagon
\draw (90:0.2) node{}-- (162:0.2) node{}-- (234:0.2) node{}-- (306:0.2) node{}-- (378:0.2) node{}-- cycle;
% draw text inside pentagon
\draw (0,0) node{10};
\stoptikzpicture%
text after symbol
它确实可以工作,但是图形/符号垂直对齐不佳,并且导致其上方出现巨大的行距,如下所示:
我该如何解决这个问题?有没有比 TikZ 更好的选择来创建这样的符号?
答案1
您可以使用baseline
键垂直对齐您的 Ti钾Z 符号:
\usemodule[tikz]
\starttext
this is a very very very very very very very very very long text before symbol%
this is a very very very very very very very very very long text before symbol%
\starttikzpicture[baseline=-3pt]
% draw pentagon
\draw (90:0.2) node{}-- (162:0.2) node{}-- (234:0.2) node{}-- (306:0.2) node{}-- (378:0.2) node{}-- cycle;
% draw text inside pentagon
\draw (0,0) node{10};
\stoptikzpicture%
text after symbol
\stoptext
默认 Ti钾Z 将图片的下端放在基线上。如果您从五边形中删除所有节点,并从保存 10 的节点中删除填充,则可以获得良好的结果,而无需手动将其与键对齐baseline
:
\usemodule[tikz]
\starttext
this is a very very very very very very very very very long text before symbol%
this is a very very very very very very very very very long text before symbol%
\starttikzpicture
% draw pentagon
\draw (90:0.2) -- (162:0.2) -- (234:0.2) -- (306:0.2) -- (378:0.2) -- cycle;
% draw text inside pentagon
\draw (0,0) node[inner sep=0pt]{10};
\stoptikzpicture%
text after symbol
\stoptext
答案2
除了 TikZ,您还可以使用 MetaFun,它可以很好地与 ConTeXt 集成,并且比 TikZ 快几个数量级。
\startuniqueMPgraphic{pentagon}
R := 2 / (1 + sqrt(5)) * max(OverlayWidth, OverlayHeight) ;
draw (0, R) for i = 1 upto 4:
-- (R * cosd(90 + i*72), R * sind(90 + i*72))
endfor -- cycle ;
setbounds currentpicture to fullsquare xyscaled(OverlayWidth, OverlayHeight) ;
\stopuniqueMPgraphic
\defineoverlay
[pentagon]
[\uniqueMPgraphic{pentagon}]
\defineframed
[pentagonframed]
[background=pentagon,
frame=off,
location=low]
\starttext
\samplefile{lorem}%
\pentagonframed{10}
\samplefile{lorem}%
\stoptext