6

I have this macro for showing rating/review. In the macro, it's a star symbol which works great. I tried to change star symbol to circle but it did not work as I expected. I would like to see circle symbol instead of star symbol in rating. Thanks in advance for all the help.

Following is MWE:

\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?"blue!70":"lightgray")}
    \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=blue!70]  {};
  \fi,

\end{tikzpicture}
}

\begin{document}

 \section*{Languages}
 \textbf{English}\hspace{-1mm}\small{\score{5}{5}}\\
 \textbf{Spanish}\hspace{-1mm}\small{\score{2.4}{5}}\\
 \textbf{French}\hspace{-1mm}\small{\score{1.5}{5}}

\end{document}
  • 1
    The star code is from http://tex.stackexchange.com/q/11390/2552, right? Maybe for your purposes, http://tex.stackexchange.com/questions/301012/how-to-create-dotted-counter works better. – Jake Apr 08 '16 at 09:16
  • @Jake Yes. The problem with that it does not fill the half circle. Thanks though. – Santosh M. Apr 08 '16 at 09:36

1 Answers1

8

Following code uses circle instead of star and adjust clipping corners from star to circle.

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{shapes.geometric,calc}

\newcommand\score[2]{

\pgfmathsetmacro\pgfxa{#1+1}

\tikzstyle{scorestars}=[circle, draw, inner sep=0.15em,anchor=west]

\begin{tikzpicture}[baseline]
  \foreach \i in {1,...,#2} {
    \pgfmathparse{(\i<=#1?"blue!70":"lightgray")}
    \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.north west) rectangle 
    ($(star\partstar.south west)!\starpart!(star\partstar.south east)$);
    \fill (\partstar*1em,0) node[scorestars,fill=blue!70]  {};
  \fi,

\end{tikzpicture}
}

\begin{document}

 \section*{Languages}
 \textbf{English}\hspace{-1mm}\small{\score{5}{5}}\\
 \textbf{Spanish}\hspace{-1mm}\small{\score{2.4}{5}}\\
 \textbf{French}\hspace{-1mm}\small{\score{1.5}{5}}

\end{document}

enter image description here

Ignasi
  • 136,588
  • Thanks a lot. I do not understand why tikzpicture is getting on new line? I would prefer on the same line as text preceding it. – Santosh M. Apr 08 '16 at 11:54
  • @user3669801 It's placed on a new line because \score command contains empty lines which, you know, they mean start a new paragraph. Just suppress all those empty lines and circles will be at same line than corresponding language. You probably will want to suppress alse [baseline] from tikzpicture. – Ignasi Apr 08 '16 at 14:06
  • your coloring is not smooth despite the original code in the question! When I change the size and spacing of circles, it gets really bad! :( – Hosein Rahnama Nov 28 '17 at 18:43