我有这个宏来显示评级/评论。在宏中,它是一个星号,效果很好。我试图将星号改为圆圈,但没有按预期工作。我希望在评级中看到圆圈符号而不是星号符号。提前感谢大家的帮助。
以下是 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
以下代码使用circle
而不是star
并调整剪辑角从star
到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}