如何在tikz中使用lastpage代表的数字

2019-10-29 13:17发布

在[https://tex.stackexchange.com/questions/11390/drawing-stars-similar-with-tikz](https://tex.stackex...

在[https://tex.stackexchange.com/questions/11390/drawing-stars-similar-with-tikz](https://tex.stackexchange.com/questions/11390/drawing-stars-similar-with-tikz)看到了五角星的画法,想用在书中代表进度。MWE: ```tex \documentclass{article} \usepackage{lastpage} \usepackage{tikz} \usetikzlibrary{shapes.geometric,calc} \newcommand\score[2]{ \pgfmathsetmacro\pgfxa{#1+1} \tikzstyle{scorestars}=[star, star points=5, star point ratio=2.25, draw,inner sep=0.15em,anchor=outer point 3] \begin{tikzpicture}[baseline] \foreach \i in {1,...,#2} { \pgfmathparse{(\i<=#1?"yellow":"gray")} \edef\starcolor{\pgfmathresult} \draw (\i*1em,0) node[name=star\i,scorestars,fill=\starcolor] {}; } \pgfmathparse{(#1>int(#1)?int(#1+1):0} \let\partstar=\pgfmathresult \ifnum\partstar>0 \pgfmathsetmacro\starpart{#1-(int(#1))} \path [clip] ($(star\partstar.outer point 3)!(star\partstar.outer point 2)!(star\partstar.outer point 4)$) rectangle ($(star\partstar.outer point 2 |- star\partstar.outer point 1)!\starpart!(star\partstar.outer point 1 -| star\partstar.outer point 5)$); \fill (\partstar*1em,0) node[scorestars,fill=yellow] {}; \fi ,\end{tikzpicture} } \begin{document} \score{5*\thepage/\pageref{LastPage}}{5} \end{document} ``` `\pageref{LastPage}`用在这里会报错,换作纯数字没有问题,该如何才能成功使用最后一页的页数?
1条回答
论坛 github.com/C
2019-10-29 13:35
首先,`\pageref{...}` 的输出不一定是数字,例如第一次编译时输出的是问号,所以不能直接使用它,要判断该引用(对应 `\r@

一周热门 更多>

相关问答