I'm writing a review for a book at the moment, and I thought I'd be clever and show off what LaTeX is capable of by adding a x-out-of-y stars graphic. Tikz can do many things so I would have thought that a trick like this would be fairly trivial, however it seems that I cannot figure out a macro to draw the shapes at the right size, let alone fancy tricks such as half-filled stars or something similar. I think the code I have so far might be headed in the right direction:
\usepackage{tikz}
\usetikzlibrary{shapes.geometric}
\usetikzlibrary{calc,shadows}
\newcommand*\starfill{%
\tikz[baseline=(key.base),scale=-3]
\node[star, star points=5, star point ratio=2.25, fill=black, draw](key) {S};
}
I've tried to start by drawing a single star shape, but ideally I'd like to define like \starsranking{number}{total}
that will output the appropriate shaded number
of stars out of total
. Is this doable? It doesn't sound particularly difficult.
star, star points=5, star point ratio=2.25
are your own options, aren't there? You should have a look at\foreach
. You need two: one from 1 to\starpoints
to make the filled stars and one for\starpoints+1
to 5. The half-filled stars should be do-able with an clipped fill-path.