Good way to make \textcircled numbers?
Here's a TikZ solution:
\documentclass{article}
\usepackage{tikz}
\newcommand*\circled[1]{\tikz[baseline=(char.base)]{
\node[shape=circle,draw,inner sep=2pt] (char) {#1};}}
\begin{document}
Numbers aligned with the text: \circled{1} \circled{2} \circled{3} end.
\end{document}
It's just a node. TikZ options are used to align the base line, to adjust the size and to get the circle shape. You're free to choose further options regarding size or circle thickness (option thick
). There's more: for example you could even name the nodes by another argument to connect them by arrows later.
If one like to use it for an enumerated list, for example, it's easy but has to be protected:
\usepackage{enumitem}
...
\begin{enumerate}[label=\protect\circled{\arabic*}]
\item First item
\item Second item
\item Third item
\item Fourth item
\end{enumerate}
I was pleasantly surprised how many people decided to give it a try, and a lot of interesting solutions popped out. As per tradition, this answer will be community wiki and will summarize and compare all suggested solutions.
I hereby suggest three different evaluation criteria, each graded from 1 to 5:
- Simplicity. This is a measure how easy it is to use the proposed solution. Points deducted for using additional packages, or defining anything other than a simple convenience macro.
- Flexibility. This primarily includes how easy is to use this in other contexts, in this case different frame shapes, sizes and thicknesses.
- Accuracy. Simply put, how aesthetically pleasing the solution looks, particularly how well the glyph is centered in the circlce, and how it fits surrounding free-running text.
Here we go:
The
raisebox
solution.Thanks to Jimi Oke for the fast fingers. This came in first, and is the one that I particularly like for the application I had in mind. It comes as easy as:
\raisebox{.5pt}{\textcircled{\raisebox{-.9pt} {8}}}
Nothing more than that. On the simplicity front, it doesn't get any better than this. Solid 5/5, as no extra packages are needed, and the unwieldy definition can be trivially abstracted in a one-liner
\def
.Flexibiltiy-wise, this solution rates quite low, as you have no control on the circle size or parameters (I'm sure that some TeX hackers would prove me wrong, but for the love of $DEITY, spare us such abominations). 2/5 is well-deserved here. {1}
The accuracy issue is subjective as always, but you'd need to play around with the vertical distances to get it Just Right (tm) for the typeface you have selected. 2/5.
The
ding
-y solution.This came in from TH. that suggests using some predefined symbol glyphs. The omniscient symbols-a4 document says that The One True Way to do it is to use:
\usepackage{pifont} \ding{172}--\ding{181} % seriffed fonts \ding{192}--\ding{201} % sans-seriffed fonts
Or even the Go board nomenclature:
\usepackage{igo} \whitestone{1}--\whitestone{99}
On the simplicity side, this rates at 4.5/5, although I'm reluctant to give it a straigt 5 due to the extra packages involved.
This is not flexible at all. If you don't like the glyphs, you're on your own. 1/5.
The glyphs themselves are well-designed, as one should expect, and the numbers are visually well-aligned with the circles. Although if you have a a typeface with a distinct style, the numbers font might not mesh well with the text.
The obligatory
tikz
solution.Ahh, there's always that, isn't it. This is due to Stefan Kottwitz.
\usepackage{tikz} \newcommand*\circled[1]{\tikz[baseline=(char.base)]{ \node[shape=circle,draw,inner sep=2pt] (char) {#1};}} \begin{document} Numbers aligned with the text: \circled{1} \circled{2} \circled{3} end. \end{document}
Personally, I'm not into
tikz
(I know, I should learn it one of these days), so going with this would be a one-off use of the package for me, which I'd like to avoid. I can't give more than 2/5 here, but thetikz
fanboiz (and galz!) should bump this up all the way to 4/5.As far as flexibility is concerned: this is the real deal. Stefan demonstrated even how to use the circled symbols with enumerated lists, of all things. Different frame shapes are certainly possible, with varying degree of fit around the glyph. Indisputable 5/5.
Baseline alignment is top-notch without playing around with some manual adjustments, which is quite nice. The spacing around the symbol looks all right, although in free-running text the circle should preferably have a tighter fit around the number, which can be achieved by playing around with the
inner sep
parameter in the command definition. 5/5 here.pict2e
/picture
solutionA late addition by Herbert proposes uses some basic primitives from the
picture
andpict2e
packages. Here goes:\usepackage{pict2e,picture} \newsavebox\CBox \newlength\CLength \def\Circled#1{\sbox\CBox{#1}% \ifdim\wd\CBox>\ht\CBox \CLength=\wd\CBox\else\CLength=\ht\CBox\fi \makebox[1.5\CLength]{\makebox(0,1.5\CLength){\put(0,0){\circle{1.5\CLength}}}% \makebox(0,1.5\CLength){\put(-.5\wd\CBox,0){#1}}}}
On the simplicity front, this doesn't rate too well. It looks a bit convoluted, although definitely understandable after studying it, and uses two additional packages. 2/5 is a reasonable score here.
Flexibility is not quite built-in, but is certainly possible. The circle radius can be adjusted, by modifying the
1.5
factor, and the baseline adjustment can be played with. 3.5/5.As it stands in this definition, the baseline of the surrounding text is tangent to the circle instead of being aligned with the circled number base. This might be desirable in some circumstances, but the numbers look a bit out of place in this way. Better results are achievable with some additional calculations when placing the boxes, and a 3.5/5 is given here to reflect this potential.
The other obligatory
tikz
solutionMatthew Leingang and morbusg tried their hand in this, and while their efforts are certainly appreciated, I feel Stefan's solution is simpler. I am grateful for the effort (and your humbleness), and I upvoted both your answers.
Final score:
- Simplicity :
raisebox
- Flexibility :
tikz
- Accuracy: tied between
tikz
andding
Overall: tikz
, without hesitation (acclamation from the public, hats thrown, handkerchiefs waved and all that).
Finally, some test code:
\documentclass{article}
\usepackage{pict2e,picture} % picture
\usepackage{tikz} % tikz
\usepackage{pifont} % ding
% Picture solution
\newsavebox\CBox
\newlength\CLength
\def\numcircledpict#1{\sbox\CBox{#1}%
\ifdim\wd\CBox>\ht\CBox \CLength=\wd\CBox\else\CLength=\ht\CBox\fi
\makebox[1.5\CLength]{\makebox(0,1.5\CLength){\put(0,0){\circle{1.5\CLength}}}%
\makebox(0,1.5\CLength){\put(-.5\wd\CBox,0){#1}}}}
% TikZ solution
\newcommand*\numcircledtikz[1]{\tikz[baseline=(char.base)]{
\node[shape=circle,draw,inner sep=1.2pt] (char) {#1};}}
% Modified \textcircled solution
\newcommand*\numcircledmod[1]{\raisebox{.5pt}{\textcircled{\raisebox{-.9pt} {#1}}}}
\begin{document}
\begin{tabular}{l|l}
Original & Lorem \textcircled{1} ipsum \textcircled{2} dolor \\
Modified & Lorem \numcircledmod{1} ipsum \numcircledmod{2} dolor\\
TikZ & Lorem \numcircledtikz{1} ipsum \numcircledtikz{2} dolor\\
Picture & Lorem \numcircledpict{1} ipsum \numcircledpict{2} dolor\\
Ding serif & Lorem \ding{172} ipsum \ding{173} dolor\\
Ding sans & Lorem \ding{192} ipsum \ding{193} dolor\\
\end{tabular}
\end{document}
{1} If somebody does decide to write such a thing, let me know and I will include it in this answer at no additional cost, but be advised that the post will be subsequently marked \textcircled{18+}
to protect the faint of heart.
The quickest fix would be to use the \raisebox
command. I've played around with it a bit, and it seems lowering the text by 0.9pt puts the figure approximately in the center:
\textcircled{\raisebox{-0.9pt}{8}}
You could play around with it to get the absolute center but it's definitely between 0.9 and 1pt. I got the idea here. It seems the \textcircled
command works best for text! But, anyway, this should solve your problem.