Created
September 28, 2013 17:47
-
-
Save jvrplmlmn/6744561 to your computer and use it in GitHub Desktop.
A small LaTeX script to get an X out of Y rating using colored stars. Requires the tikz package
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| % Example of x-out of-y rating using stars | |
| % http://tex.stackexchange.com/questions/11390/drawing-stars-similar-with-tikz | |
| \documentclass{minimal} | |
| \usepackage{tikz} | |
| \usetikzlibrary{shapes.geometric} | |
| \newcommand\score[2]{ | |
| \pgfmathsetmacro\pgfxa{#1+1} | |
| \tikzstyle{scorestars}=[star, star points=5, star point ratio=2.25, draw, inner sep=1.3pt, anchor=outer point 3] | |
| \begin{tikzpicture}[baseline] | |
| \foreach \i in {1,...,#2} { | |
| \pgfmathparse{(\i<=#1?"red":"black")} | |
| \edef\starcolor{\pgfmathresult} | |
| \draw (\i*1.75ex,0) node[name=star\i,scorestars,fill=\starcolor] {}; | |
| } | |
| \end{tikzpicture} | |
| } | |
| \newcommand\customscore[4]{ | |
| \pgfmathsetmacro\pgfxa{#1+1} | |
| \tikzstyle{scorestars}=[star, star points=5, star point ratio=2.25, draw, inner sep=1.3pt, anchor=outer point 3] | |
| \begin{tikzpicture}[baseline] | |
| \foreach \i in {1,...,#2} { | |
| \pgfmathparse{(\i<=#1?"#3":"#4")} | |
| \edef\starcolor{\pgfmathresult} | |
| \draw (\i*1.75ex,0) node[name=star\i,scorestars,fill=\starcolor] {}; | |
| } | |
| \end{tikzpicture} | |
| } | |
| \begin{document} | |
| \score{0}{5} 0 out of 5 | |
| \score{1}{5} 1 out of 5 | |
| \score{2}{5} 2 out of 5 | |
| \score{3}{5} 3 out of 5 | |
| \score{4}{5} 4 out of 5 | |
| \score{5}{5} 5 out of 5 | |
| \score{0}{3} 0 out of 3 | |
| \score{1}{3} 1 out of 3 | |
| \score{2}{3} 2 out of 3 | |
| \score{3}{3} 3 out of 3 | |
| \customscore{2}{3}{blue}{black} | |
| \customscore{2}{3}{orange}{black} | |
| \customscore{2}{3}{yellow}{gray} | |
| \customscore{2}{3}{white}{black} | |
| Rating: \customscore{2}{3}{black}{white} 2 out of 3 | |
| Raaaaaating: \customscore{2}{3}{black}{white} 2 out of 3 | |
| Raaaaaaaaaaaating: \customscore{2}{3}{black}{white} 2 out of 3 | |
| \end{document} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment