Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I'm trying to make some good-looking numbers in a circle, using the simple command:

\textcircled{1}

However, the circle is misaligned vertically with the number, and look a bit sloppy:

alt text

Any suggestions how can I adjust the vertical alignment so that the numbers look more centered w.r.t to the circles? Or, if that's not an option, what other ways to achieve the same results are possible?

I will use those only for numbers, and in very few places, so manual adjustment per glyph is an option.

I'm using pdfLaTeX with Computer Modern, if that matters.

share|improve this question
    
Got two good answers here, for less than 30 minutes (you guys are fast!). I'll probably make a community wiki answer summarizing all options one of these days, maybe some other solutions will come along in the meantime. –  Martin Tapankov Dec 13 '10 at 9:58
    
I'm sleep-deprived, that's why! –  Jimi Oke Dec 13 '10 at 10:08
    
What package provides \textcircled? –  Matthew Leingang Dec 13 '10 at 13:08
    
@Matthew: It seems to be built-in with LaTeX. Works out of the box. –  Martin Tapankov Dec 13 '10 at 13:24
1  
You could use Unicode. U+2460-2473 for 1 to 20, U+24EA for 0, U+3251-325F for 21-35, and U+32B1-32BF for 36-50. –  user41833 Nov 28 '13 at 3:10

11 Answers 11

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}

alt text

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}

alt text

share|improve this answer
    
Ahhh, about time :-) Looks pretty nice indeed. –  Martin Tapankov Dec 13 '10 at 13:27
    
@Martin: Works fine with enumerate, if protected. I cannot resist to add an example... –  Stefan Kottwitz Dec 13 '10 at 13:32
    
Sweet example! I have had problems in the past using TikZ examples inline but now I see that is solved by baseline=(char.base). Cool. –  Jimi Oke Dec 13 '10 at 15:36
2  
@Stefan: perhaps you should replace \newcommand by \DeclareRobustCommand, like that the \protect is not needed any more, which is more user friendly. –  Philippe Goutet Dec 13 '10 at 19:28
1  
Then one should use \newcommand to declare an empty command fist and then use \DeclareRobustCommand. That way, an existing command will issue an error. –  Ben Jan 9 '11 at 11:53
up vote 54 down vote accepted

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:

  1. 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.

  2. 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.

  3. 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 the tikz 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.

  4. pict2e/picture solution

    A late addition by Herbert proposes uses some basic primitives from the picture and pict2e 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.

  5. The other obligatory tikz solution

    Matthew 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 and ding

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.

share|improve this answer
1  
excellent summary, well done! Posts such as this makes this Site worthwhile. –  Yiannis Lazarides Jan 7 '11 at 18:50
    
@Yiannis It's been some time since I posted the question, but I only found time just now to polish the summary. I hope it will be of use to people with the same problem. –  Martin Tapankov Jan 7 '11 at 18:57
1  
You say, "The spacing around the symbol looks all right, although in free-running text the circle should preferably have a tighter fit around the number." This is easily fixed by changing inner sep=2pt to inner sep=1pt in the \circled command definition. –  Matt B. Jan 7 '11 at 20:33
    
@Matt: Sure -- my intention here was to point out an aesthetic issue, but I guess I wasn't quite clear on that. The info about what needs to be changed is now mentioned in the post. Thanks. –  Martin Tapankov Jan 7 '11 at 20:46
1  
@MartinTapankov The problem is solved with raisebox provided every call is preceded with \protect. –  Alexander Serebrenik Oct 18 '12 at 9:23

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.

share|improve this answer
3  
That's going to change the baseline of the numbers which might not be desirable. But perhaps with an outer \raisebox to raise the whole circled number, baselines could be maintained. –  TH. Dec 13 '10 at 9:50
    
Mais oui! I should have thought of this myself. Thanks! I'll wait a bit for some more suggestions, before I mark this as accepted. –  Martin Tapankov Dec 13 '10 at 9:53
    
@TH. True, but that doesn't matter for me -- the numbers do not appear in the free running text, but are rather headers for table columns or used for labelling. –  Martin Tapankov Dec 13 '10 at 9:55
    
But, actually, the \textcircled output already has a lower baseline with or without the \raisebox. So, if the author prefers it all flush, then he should go for pifont. With an outer \raisebox, the maximum is a 0.5pt raise, which gets the circle back to its original position, which is not flush with the text, though. Raising everything beyond 0.5pt begins to shift the number, not the circle, negating initial efforts. Thus, if the author wants a good \textcircled, then here's one: \raisebox{.5pt}{\textcircled{\raisebox{-.9pt} {8}} }. This is actually pretty good. –  Jimi Oke Dec 13 '10 at 9:59
    
@Martin: you might also get a TikZ suggestion. ;-) –  Stefan Kottwitz Dec 13 '10 at 13:11

PGF is overkill for this one application, but if you already have it loaded, you can use it:

\documentclass{article}
\usepackage{tikz}

\newcommand{\pgftextcircled}[1]{
    \setbox0=\hbox{#1}%
    \dimen0\wd0%
    \divide\dimen0 by 2%
    \begin{tikzpicture}[baseline=(a.base)]%
        \useasboundingbox (-\the\dimen0,0pt) rectangle (\the\dimen0,1pt);
        \node[circle,draw,outer sep=0pt,inner sep=0.1ex] (a) {#1};
    \end{tikzpicture}
}

\newcommand{\pangram}{\noindent{The \textcircled{0} quick \textcircled{1} brown \textcircled{2} fox \textcircled{3} jumps \textcircled{4} over \textcircled{5} the \textcircled{6} lazy \textcircled{7} dog.}
}
\begin{document}

\begin{minipage}{0.5\textwidth}
\pangram
\bigskip

\let\textcircled=\pgftextcircled
\pangram
\end{minipage}

\end{document}

snippet output

As you can see there's some extra space around the circles compared to \textcircled but it's not bad.

pre-post edit: I see Stefan and morbusg have beat me to the punch. Oh well.

share|improve this answer
    
I think an external process is indeed overkill for something that can be done inside LaTeX. You can just as simply construct it as \newcommand{\Ring}[1]{\raisebox{-1pt}{\begin{tabular}{@{}c@{}}{\small#1}\[-11.5p‌​t]\BigCircle\end{tabular}}}. Auto-adjustment of the dimensions is left as an exercise to the reader :-) –  Peter Flynn Aug 6 '11 at 18:41
    
Peter, what external process? –  u0b34a0f6ae Apr 3 '13 at 0:53
1  
@u0b34a0f6ae: I think Peter is referring to the fact that tikz uses a bunch of \special commands added after TeX processes the input. So it's “external” to the normal TeX digestion system. –  Matthew Leingang Apr 23 '13 at 18:47

From symbols.pdf, it looks like pifont can do what you want with \ding{172} through \ding{181} or \ding{192} through \ding{201}.

Or the igo package with \whitestone{1} through \whitestone{99}, although that's meant for typesetting Go boards.

It sounds like the solution has been found, but here's a simple comparison.

\documentclass{article}
\usepackage{pifont}
\def\X#1{%
        #1%
        \textcircled{#1}%
        \raisebox{.9pt}{\textcircled{\raisebox{-.9pt}{#1}}}%
        \ding{\numexpr171+#1\relax}%
}
\begin{document}
\X0\X1\X2\X3\X4\X5\X6\X7\X8\X9
\end{document}
share|improve this answer
    
This is a great solution. However, the pifonts are rather squished, compared to the \textcircled output. The pro, though, is the pifonts are flush with the text, which may be a good thing for the author. –  Jimi Oke Dec 13 '10 at 9:49
    
@TH: Nice. What does the textcomp package do? –  Jimi Oke Dec 13 '10 at 10:09
    
@Jimi: I thought it was required for \textcircled. I was incorrect. (I was looking at Table 17 of Symbols.pdf and it notes that textcomp is required for \newtie, but I wasn't reading carefully enough.) I've updated the code. –  TH. Dec 13 '10 at 23:05

morbusg already mentioned that some fonts have encircled numbers as Unicode glyphs and showed how to embed them directly. Some fonts provide a more user-friendly interface for accessing the numbers, e.g. Linux Libertine and Junicode. Obviously, this means that we’re deviating from your requirement to use Computer Modern. The advantage of these Unicode numbers presumably is that they were crafted by a font designer, so there shouldn’t be any need for fine-tuning.

Here’s a simple proof-of-concept (You also need to have the junicode package installed):

\documentclass{article}
\usepackage{fontspec}
\usepackage{libertine}

\begin{document}
\libertineGlyph{uni2460} \libertineGlyph{uni24F5} \libertineGlyph{uni2776}

{\fontspec[Ligatures=Discretionary]{Junicode}[1] [[1]] <1>}
\end{document}

output

These methods are described in the respective documentations.

Here’s an even more comfortable way of accessing these sets of numbers. The doubly circled numbers are (per Unicode) available from 1 to 10, the others from 0 to 20.

\documentclass{article}
\usepackage{fontspec}
\usepackage{libertine}
\usepackage{pgf} % for the calculation
% \libcirc and \libcircblk display their '0' if the parameter is out of range
\newcommand{\libcirc}[1]{\pgfmathparse{
    ifthenelse(#1 > 0 && #1 < 21, Hex(9311+#1), Hex(9450)
    }\libertineGlyph{uni\pgfmathresult}}
\newcommand{\libcircdbl}[1]{\pgfmathparse{Hex(9460+#1)}\libertineGlyph{uni\pgfmathresult}}
\newcommand{\libcircblk}[1]{\pgfmathparse{
    ifthenelse(#1 > 0 && #1 < 11, Hex(10101+#1),
        ifthenelse(#1 > 10 && #1 < 21, Hex(9450-10+#1),
            Hex(9471)
        )
    )
    }\libertineGlyph{uni\pgfmathresult}}

\newcommand{\juncirc}[1]{{\fontspec[Ligatures=Discretionary]{Junicode}[#1]}}
\newcommand{\juncircdbl}[1]{{\fontspec[Ligatures=Discretionary]{Junicode}[[#1]]}}
\newcommand{\juncircblk}[1]{{\fontspec[Ligatures=Discretionary]{Junicode}<#1>}}

\usepackage{pgffor} % just for the demo loop
\setlength{\parindent}{0pt} % just for the demo
\begin{document}
\section{Linux Libertine}
\foreach \x in {0,...,20} {\libcirc{\x} }

\foreach \x in {1,...,10} {\libcircdbl{\x} }

\foreach \x in {0,...,20} {\libcircblk{\x} }

\section{\fontspec{Junicode}Junicode}
\foreach \x in {0,...,20} {\juncirc{\x} }

\foreach \x in {1,...,10} {\juncircdbl{\x} }

\foreach \x in {0,...,20} {\juncircblk{\x} }
\end{document}

output

share|improve this answer
    
I think this does not work with pdflatex. –  moose Dec 18 '13 at 12:19
    
@moose Yes .. I have to check if the first code bit works with the current libertine at all (but then pdfLaTeX should be fine), the second bit is XeLaTeX/LuaLaTeX only, I should put that in the answer as well. –  doncherry Dec 18 '13 at 16:18

The mathdesign package defines \figurecircled which has better spacing for numbers than \textcircled does.

The mathdesign package is incompatible with amsfonts and amssymb but if you're using a mathdesign font anyway, that's not a problem.

share|improve this answer
1  
This answer got voted down? Could whoever did this explain why they think this is a bad solution to the problem? –  Seamus Jan 9 '11 at 11:42

With Plain (stumbled upon this by chance and remembered this question):

\def\circled#1{{\ooalign{\hfil\lower.1ex\hbox{#1}\hfil\crcr\Orb}}}
$\circled1 \circled2 \circled3 \ldots \circled9 \quad \circled{23}$
\bye

circlednums

With XeTeX:

\font\circled="Arial Unicode MS"
{\circled ➀} Didn't occur to me {\circled ➄} earlier that some fonts have {\circled ➇} these.
\bye

Or maybe with TikZ:

\input tikz
baseline ain't so pretty \par
baseline ain't so pretty \par
baseline \tikz \node[circle,draw] {2}; ain't \par
so pretty \tikz[baseline] \node[circle,draw] {2}; baseline \par
ain't so pretty baseline \par
ain't \tikz[inner sep=1pt,baseline=-.75ex] \node[circle,draw] {2}; so pretty \par
baseline \tikz[inner sep=2pt,baseline=-.75ex] \node[circle,draw] {2}; ain't so \par
pretty baseline ain't so \par
pretty \tikz[inner sep=.25ex,baseline=-.75ex] \node[circle,draw] {2}; baseline \par
... actually, now it sorta is \par
baseline ain't so pretty \par
baseline ain't so pretty
\bye

Darn, Stefan beat me to it with a nicer one.

share|improve this answer

with the default picture commands:

\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\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.2\CLength]{\makebox(0,1.2\CLength){\put(0,0){\circle{1.2\CLength}}}%
    \makebox(0,1.2\CLength){\put(-.5\wd\CBox,0){#1}}}}

\begin{document}
\Huge
foo
\Circled{1}
\Circled{2}
\Circled{ABC}

\end{document}

alt text

share|improve this answer

Even easier:

\textcircled{\small{2}}

or

{\large \textcircled{\small 2}} 

or

{\Large \textcircled{\normalsize 2}}

(sorry, can't post an image)

share|improve this answer
1  
This might work when the circle is not surrounded by text, and the font size of the number is not an issue -- but I'd rather use one of the other solutions instead. –  Martin Tapankov Jan 10 '11 at 18:31

@Stefan's answer is good, however, I improved his answer.

Firstly, if \circled{1} and \circled{10} are placed together, the two circles will not be the same size, so I added an optional parameter to the \circled command. The optional parameter was regraded as a placeholder to make sure that these circles appear in the same size.

Additionally, since I'd used \ifblank, which is provided by package etoolbox, to check if the optional parameter was provided, I used \robustify to make the command robust. This bypassed the disadvantage of using \DeclearRobustCommand, mentioned by @Stefan in a comment of his answer. Thus, the \protact is no longer needed.


Code:

\documentclass{article}
\usepackage{enumitem}
\usepackage{tikz}
\usepackage{etoolbox}
\newcommand{\circled}[2][]{%
  \tikz[baseline=(char.base)]{%
    \node[shape = circle, draw, inner sep = 1pt]
    (char) {\phantom{\ifblank{#1}{#2}{#1}}};%
    \node at (char.center) {\makebox[0pt][c]{#2}};}}
\robustify{\circled}
\begin{document}
\mbox{}\rlap{\rule{.7\linewidth}{.4pt}}%
The original version: \circled{1} and \circled{10}.

\mbox{}\rlap{\rule{.7\linewidth}{.4pt}}%
The improved version: \circled[10]{1} and \circled[10]{10}.

\newcommand{\dcircled}[1]{\circled[00]{#1}}
\begin{enumerate}[label=\dcircled{\arabic*}, noitemsep]
\item I
\item am
\item happy
\item to
\item join
\item with
\item you
\item today
\item in
\item what
\item will
\item go
\item down
\item in
\item history
\item as
\item the
\item greatest
\item demonstration
\item for
\item freedom
\item in
\item the
\item history
\item of
\item our
\item nation.
\end{enumerate}
\end{document}

Result:

share|improve this answer
    
you know the option minimum size for nodes? –  percusse yesterday
    
@percusse Sorry, but I don't understand you. –  Ch'en Meng 20 hours ago
    
You can define a minimum size for circle nodes without a box or phantom with uniform size. –  percusse 20 hours ago

protected by Community May 25 at 12:58

Thank you for your interest in this question. Because it has attracted low-quality answers, posting an answer now requires 10 reputation on this site.

Would you like to answer one of these unanswered questions instead?

Not the answer you're looking for? Browse other questions tagged or ask your own question.