最近,在wordpress找些插件总会看到这样的评分的星号,在tex里怎么实现呢? 【解决方案】 在网络上搜索了下,果然有酷代码如下: 选自:http://tex.stackexchange.com/questions/11390/drawing-stars-similar-with-tikz
\documentclass{article} \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} \small\score{2}{5} A meagre result. \Huge{\score{4.4}{5} Wooo!} \end{document}【效果图】
发表评论 取消回复