Something like this?
\documentclass{article}
\usepackage{tikz,calc}
\newlength\charwidth
\newlength\chwidth
\newcommand*\circled[1]{%
\settowidth\charwidth{#1\,\%}%
\settototalheight\chwidth{#1\,\%}%
\ifdim\chwidth>\charwidth\let\charwidth\chwidth\fi
\addtolength\charwidth{5pt}% twice inner sep plus half line width
\tikz[baseline=(char.base)]{%
\node [inner sep=2pt, circle] (char) {#1\,\%};
\draw [line width=2pt, color=basecol] (char.north) arc (90:90-#1*3.6:.5\charwidth) coordinate (a);
\draw [line width=2pt, color=othercol] (a) arc (90-#1*3.6:-270:.5\charwidth);
}%
}
\colorlet{basecol}{purple}
\colorlet{othercol}{purple!25}
\begin{document}
\circled{87.34}
\circled{34}
\circled{20.89}
\circled{0} \circled{25} \circled{50} \circled{75} \circled{100}
\end{document}
Key-Value Interface
Here's another approach if you want to be able to configure things to a greater extent:
\documentclass{article}
\usepackage{tikz,calc}
\makeatletter
\tikzset{
circled/.code={
\tikzset{%
/circled/.cd,
#1
}
},
circled defaults/.code={
\tikzset{%
circled={%
base=blue!50!magenta,
other=gray!25,
sep=2pt,
width=2pt,
}
}
},
/circled/.cd,
base/.store in=\circled@basecol,
other/.store in=\circled@othercol,
sep/.store in=\circled@sep,
width/.store in=\circled@width,
/tikz/circled defaults,
}
\newlength\charwidth
\newlength\chwidth
\newdimen\circled@cw
\newdimen\circled@cs
\newcommand*\circled[2][]{%
\tikzset{%
circled defaults,
circled={#1}
}%
\settowidth\charwidth{#2\,\%}%
\settototalheight\chwidth{#2\,\%}%
\ifdim\chwidth>\charwidth\let\charwidth\chwidth\fi
\circled@cw=\circled@width
\circled@cs=\circled@sep
\addtolength{\charwidth}{2\circled@cs+.5\circled@cw}% twice inner sep plus half line width
\tikz[baseline=(char.base)]{%
\node [inner sep=\circled@sep, circle] (char) {#2\,\%};
\draw [line width=\circled@width, color=\circled@basecol] (char.north) arc (90:90-#2*3.6:.5\charwidth) coordinate (a);
\draw [line width=\circled@width, color=\circled@othercol] (a) arc (90-#2*3.6:-270:.5\charwidth);
}%
}
\makeatother
\begin{document}
\circled{87.34} \circled[base=red, other=green, sep=10.2pt, width=5.5pt]{34} \circled[base=green!50!blue!50, width=3pt]{20.89}
\end{document}
EDIT
I'm not sure what the issue with alignment is: my circles get aligned left, as I'd expect. It may be that what you really want are circles of the same size, regardless of content.
This version modifies the code above to allow this and the example shows the contrast between the dynamically-sized circles and those taking a standard size.
\documentclass{article}
\usepackage{tikz,calc}
\makeatletter
\newif\ifcircled@makesize
\tikzset{
circled/.code={
\tikzset{%
/circled/.cd,
#1
}
},
circled defaults/.code={
\tikzset{%
circled={%
base=blue!50!magenta,
other=gray!25,
sep=2pt,
width=2pt,
}
}
},
circled size/.style={%
circled={%
make size=true,
size=#1,
}
},
/circled/.cd,
base/.store in=\circled@basecol,
other/.store in=\circled@othercol,
sep/.store in=\circled@sep,
width/.store in=\circled@width,
size/.store in=\circled@size,
make size/.is if=circled@makesize,
make size=false,
size=0pt,
/tikz/circled defaults,
}
\newlength\charwidth
\newlength\chwidth
\newdimen\circled@cw
\newdimen\circled@cs
\newcommand*\circled[2][]{%
\tikzset{%
circled defaults,
circled={#1}
}%
\circled@cw=\circled@width
\ifcircled@makesize
\circled@cs=\circled@size
\setlength\charwidth{\circled@cs}%
\addtolength{\charwidth}{.5\circled@cw}% half line width
\tikz[baseline=(char.base)]{%
\node [text width=\circled@cs, align=center] (char) {#2\,\%};
\draw [line width=\circled@width, color=\circled@basecol] ([yshift=.5\charwidth]char.center) arc (90:90-#2*3.6:.5\charwidth) coordinate (a);
\draw [line width=\circled@width, color=\circled@othercol] (a) arc (90-#2*3.6:-270:.5\charwidth);
}%
\else
\settowidth\charwidth{#2\,\%}%
\settototalheight\chwidth{#2\,\%}%
\ifdim\chwidth>\charwidth\let\charwidth\chwidth\fi
\circled@cs=\circled@sep
\addtolength{\charwidth}{2\circled@cs+.5\circled@cw}% twice inner sep plus half line width
\tikz[baseline=(char.base)]{%
\node [inner sep=\circled@sep, circle] (char) {#2\,\%};
\draw [line width=\circled@width, color=\circled@basecol] (char.north) arc (90:90-#2*3.6:.5\charwidth) coordinate (a);
\draw [line width=\circled@width, color=\circled@othercol] (a) arc (90-#2*3.6:-270:.5\charwidth);
}%
\fi
}
\makeatother
\begin{document}
\noindent\circled{87.34} \circled[base=red, other=green, sep=10.2pt, width=5.5pt]{34} \circled[base=green!50!blue!50, width=3pt]{20.89}
\noindent\circled{0} \circled{25} \circled{50} \circled{75} \circled{100}
\tikzset{circled size=40pt}% switch to circles of standard size
\noindent\circled{87.34}
\noindent\circled{34}
\noindent\circled[base=green!50!blue!50]{20.89}
\noindent\circled{0} \circled{25} \circled{50} \circled{75} \circled{100}
\end{document}
If using standard sizing, the sep=<dimension>
has no effect. However, the line width=<dimension>
and colour options are still effective. But if you change the line width for only some circles, it will break the standard sizing, so you probably only want to alter colours on a per-circle basis in this case.
Note that it is important to set a sufficiently large size because the circles will not be adjusted if the contents is too big: the circles will remain the size you set regardless of the width and height of the contents.
%
is added by the macro rather than specified in the argument? Only because the code is easier that way.%
can be added automatically.