306

This question led to a new package:
circledsteps

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.

14
  • 1
    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. Commented Dec 13, 2010 at 9:58
  • 4
    What package provides \textcircled? Commented Dec 13, 2010 at 13:08
  • 3
    @Matthew: It seems to be built-in with LaTeX. Works out of the box. Commented Dec 13, 2010 at 13:24
  • 6
    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
    Commented Nov 28, 2013 at 3:10
  • 4
    As of 2022-09-26, the standard \textcircled{0}\textcircled{9} in Computer Modern are better than in the OP. Namely, running pdflatex on pastebin.com/raw/fwY6wFz9 yields i.imgur.com/nDZZ14q.png . Here, most circles don't touch the digits, whereas in the OP, all circles visibly touch the digits.
    – user224332
    Commented Sep 25, 2022 at 23:19

17 Answers 17

331

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

17
  • 1
    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
    Commented Dec 13, 2010 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. Commented Dec 13, 2010 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
    Commented Jan 9, 2011 at 11:53
  • 1
    @LuisFelipeVillavicencioLopez Sure! Comments are not the best for code discussions. Perhaps post a new question, or let's talk at the LaTeX Community where I post daily.
    – Stefan Kottwitz
    Commented Sep 24, 2015 at 21:29
  • 2
    It seems that you cannot use this in caption? Can this be changed?
    – TimK
    Commented Jul 8, 2018 at 6:25
183

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.

9
  • 9
    excellent summary, well done! Posts such as this makes this Site worthwhile.
    – yannisl
    Commented Jan 7, 2011 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. Commented Jan 7, 2011 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.
    – mbauman
    Commented Jan 7, 2011 at 20:33
  • 2
    @MartinTapankov The problem is solved with raisebox provided every call is preceded with \protect. Commented Oct 18, 2012 at 9:23
  • 1
    maybe it worth mentioning that if you are going to use TikZ new command inside a caption you should put after \protect command. it took me while to figure this out!
    – Foad
    Commented Jul 27, 2017 at 20:41
43

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.

7
  • 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.
    Commented Dec 13, 2010 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. Commented Dec 13, 2010 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. Commented Dec 13, 2010 at 9:55
  • 1
    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
    Commented Dec 13, 2010 at 9:59
  • @Martin: you might also get a TikZ suggestion. ;-)
    – Stefan Kottwitz
    Commented Dec 13, 2010 at 13:11
33
+300

this answer has been converted in a package on CTAN: https://ctan.org/pkg/circledsteps

The answers here are all nice, and especially the tikz one is greatly configurable. But it has a problem: you can't use it inside other tikzpictures safely. So I merged a couple of things and implemented this:

\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{tikz}

\makeatletter
% Based on https://tex.stackexchange.com/questions/7032/good-way-to-make-textcircled-numbers
%
\usepackage{pict2e,picture}
\pgfkeys{/csteps/inner ysep/.initial=4pt,
    /csteps/inner xsep/.initial=4pt,
    /csteps/inner color/.initial=red,
    /csteps/outer color/.initial=blue,
}
\newsavebox\csteps@CBox
\newlength\csteps@XLength \newlength\csteps@YLength \newlength\csteps@YDepth \newlength\csteps@tmplen
\def\csteps@CircledParam#1#2{\sbox\csteps@CBox{#2}%
    \csteps@XLength=\wd\csteps@CBox\advance\csteps@XLength by\pgfkeysvalueof{/csteps/inner xsep}\relax
    \csteps@tmplen=\pgfkeysvalueof{/csteps/inner ysep}\relax
    \csteps@YDepth=\dp\csteps@CBox\advance\csteps@YDepth by 0.5\csteps@tmplen\relax
    \csteps@YLength=\ht\csteps@CBox\advance\csteps@YLength by\dp\csteps@CBox\advance\csteps@YLength by\pgfkeysvalueof{/csteps/inner ysep}\relax
    \typeout{DBG:#2\space X\space\the\csteps@XLength\space Y:\the\csteps@YLength\space D:\the\csteps@YDepth}%
    \raisebox{-#1\csteps@YDepth}{%
    \ifdim\csteps@XLength>\csteps@YLength
    \makebox[\csteps@XLength]{% X bigger than Y
        \makebox(0,\csteps@YLength){%
            \color{\pgfkeysvalueof{/csteps/outer color}}\put(0,0){\oval(\csteps@XLength,\csteps@YLength)}%
        }%
    \makebox(0,\csteps@YLength){%
        \put(-.5\wd\csteps@CBox,0){\textcolor{\pgfkeysvalueof{/csteps/inner color}}{#2}}%
    }}%
    \else
    \makebox[\csteps@YLength]{%
        \makebox(0,\csteps@YLength){%
            \color{\pgfkeysvalueof{/csteps/outer color}}\put(0,0){\circle{\csteps@YLength}}%
        }%
    \makebox(0,\csteps@YLength){%
        \put(-.5\wd\csteps@CBox,0){\textcolor{\pgfkeysvalueof{/csteps/inner color}}{#2}}%
     }}%
    \fi
    }%
}
\def\Circled#1{\csteps@CircledParam{1}{#1}}
\def\CircledTop#1{\csteps@CircledParam{0}{#1}}
\makeatother

\begin{document}
  This is normal text \Circled{1} is on the baseline, \CircledTop{2} is on top.
  \par\bigskip
  This is more evident if you have descendent, like p:\Circled{p} and \CircledTop{p}.
  \par\bigskip
  For big horizontal things it becomes oval: \Circled{200} or \CircledTop{199}.
  \par\bigskip
  Inside \texttt{tikz}
  \begin{tikzpicture}[scale=0.8, rotate=30, text width=3cm, transform shape]
      \node [draw,color=green!50!black]{text \Circled{1}};
  \end{tikzpicture}
  \par\bigskip
  \tikzset{/csteps/inner ysep=10pt}
  \tikzset{/csteps/inner xsep=10pt}
  More space: \Circled{1}  \Circled{2} \Circled{p} \Circled{200} \Circled{199}.
\end{document}

Example of use

9
  • 2
    Looks great! (+1)
    – user121799
    Commented Jun 20, 2019 at 18:06
  • The above CircledSteps code works perfectly as a MWE, but when I try to insert the code into my project I get the following error: "! LaTeX Error: Command \csteps@CBox already defined. Or name \end... illegal, see p.192 of the manual." Any thoughts on what is happening would be greatly appreciated! Note:The same error occurs when the extra comma (,) is removed from the end of the line "/csteps/outer color/.initial=blue," ... Thanks! Commented Sep 26, 2021 at 5:34
  • Re CircledSteps code: I also double-checked to make sure there were no other instances of \csteps@CBox already defined ... Thanks! Commented Sep 26, 2021 at 5:43
  • Please, try to recreate the problem with a minimal example (a complete one) and I'll try to help. You can post a question here and ping me in a comment or open an issue on GitHub github.com/Rmano/circledsteps/issues. I can't do much without an example...
    – Rmano
    Commented Sep 26, 2021 at 14:44
  • Is there a way to turn off the automatic switch to oval for "big horizontal things"? Something as small as the letter M leads to the circle becoming oval, which makes the package unusable for my case
    – ScumCoder
    Commented Oct 25, 2023 at 16:51
26

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

2
  • 6
    I think this does not work with pdflatex. Commented Dec 18, 2013 at 12:19
  • 1
    @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
    Commented Dec 18, 2013 at 16:18
24

Even easier:

\textcircled{\small{2}}

or

{\large \textcircled{\small 2}} 

or

{\Large \textcircled{\normalsize 2}}

[ed. Segletes, providing MWE & image]

\documentclass{article}  
\usepackage{enumitem}
\begin{document}

\begin{enumerate}[label=\large\protect\textcircled{\small\arabic*}]
\item First item
\item Second item
\item Third item
\item Fourth item
\end{enumerate}

    \textcircled{\small{2}}

or

    {\large \textcircled{\small 2}} 

or

    {\Large \textcircled{\normalsize 2}}
\end{document}

LaTeX rendering of the above .tex file

6
  • 2
    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. Commented Jan 10, 2011 at 18:31
  • Can we invert the colours inside the circle?
    – hola
    Commented Sep 30, 2020 at 3:57
  • I like the simplicity of this zero-dependency answer. I had luck with \textcircled{\tiny{M}}.
    – mcp
    Commented Feb 24, 2022 at 0:14
  • This solution is better suited for text. \textcircled{\small{M}} and \textcircled{\tiny{M}} both work better than \Circled{M} as \Circled{M} will make an oblong circle around the 'M'.
    – mcp
    Commented Feb 24, 2022 at 0:30
  • 1
    I've also found {\small{\textcircled{\tiny{M}}}} useful.
    – mcp
    Commented Feb 24, 2022 at 0:47
20

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.

3
  • 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.5pt]\BigCircle\end{tabular}}}. Auto-adjustment of the dimensions is left as an exercise to the reader :-) Commented Aug 6, 2011 at 18:41
  • Peter, what external process? Commented Apr 3, 2013 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. Commented Apr 23, 2013 at 18:47
20

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}

enter image description here

4
  • 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
    Commented Dec 13, 2010 at 9:49
  • @TH: Nice. What does the textcomp package do?
    – Jimi Oke
    Commented Dec 13, 2010 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.
    Commented Dec 13, 2010 at 23:05
  • 1
    @PatrickT Thanks for the image. It's a good addition.
    – TH.
    Commented Feb 12, 2019 at 18:57
17

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.

3
  • 2
    This answer got voted down? Could whoever did this explain why they think this is a bad solution to the problem?
    – Seamus
    Commented Jan 9, 2011 at 11:42
  • I didn't downvote you but I did get an error with a simple test file. Can you provide a MWE? My error message: ! TeX capacity exceeded, sorry [input stack size=5000]. \figurecircled ->\MDB-cmd \figurecircled \MDB\figurecircled l.14 ...footnote{of the emergency} $\figurecircled {1}$ ! ==> Fatal error occurred, no output PDF file produced! Commented Jul 3, 2017 at 19:34
  • In the middle of page 6 of mathdesign-doc.pdf from 2013-08-29, we see “\figurecircled{1} gives 1 (better than \textcircled{1}: ①).” Something is wrong.
    – user224332
    Commented Sep 26, 2022 at 1:10
14

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


(source: sinaimg.cn)

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:


(source: sinaimg.cn)

4
  • 1
    you know the option minimum size for nodes?
    – percusse
    Commented Dec 20, 2014 at 18:13
  • @percusse Sorry, but I don't understand you.
    – Ch'en Meng
    Commented Dec 21, 2014 at 12:30
  • You can define a minimum size for circle nodes without a box or phantom with uniform size.
    – percusse
    Commented Dec 21, 2014 at 12:33
  • 2
    @percusse That's a good suggestion, however, I don't think you understand the idea in my post. I designed this optional parameter to uniform the size of the circles, since different sized circles that are aligned together will give a unfriendly looking.
    – Ch'en Meng
    Commented Dec 23, 2014 at 10:04
11

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.

9

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

5

Here is a \pdfliteral solution. It only works for single numbers.

\def\circled#1{%
  #1%
  \pdfliteral{
    q .5 w
    10 0 0 10 -2.5 3.5 cm .05 w .5 0 m
    .5 .276 .276 .5 0 .5 c -.276 .5 -.5 .276 -.5 0 c
    -.5 -.276 -.276 -.5 0 -.5 c .276 -.5 .5 -.276 .5 0 c h
    S Q
  }%
}
\circled{1} a
\circled{2} b
\circled{3} c
\circled{10}
\bye

enter image description here

4
  • Why the coordinate transformations ?
    – percusse
    Commented Nov 23, 2015 at 6:07
  • @percusse Actually, I just copied code from here and modified it a little. If you can provide any resources to learn more about PDF coding, I would be really happy. Commented Nov 23, 2015 at 8:09
  • 1
    It is actually PostScript but PDF also supports many graphics objects. So it's a bit cumbersome to understand the set of all operators supported in PDF. But at least to start reading this code you can use the reference guide adobe.com/content/dam/Adobe/en/devnet/acrobat/pdfs/…. Also in the ISO spec (table 59 in adobe.com/devnet/pdf/pdf_reference.html ) you can recognize the TikZ operators mapped to frontend ;). The initial problem to grasp is setting up the bounding box the rest is usual PS notation.
    – percusse
    Commented Nov 23, 2015 at 8:43
  • @percusse Does your comment imply that the above could also work for latex+dvips compilation into a .ps file?
    – user224332
    Commented Sep 26, 2022 at 1:05
5

Using pifont package and symbols from \ding{172} to \ding{211} you easily have very excellent circled numbers, but if you want circled numbers bigger than 10 we have a problem. As showed by other stackexchange users here, we can solve the problem if numbers are not too big, but things became hard (complex LaTeX codes) and we can have problems if we are writing inside a text (if the circle became big, LaTeX can be forced to enlarge space between lines, or maybe to overlap circle upon adjacent upper and lower lines): things are a bit simpler if we only want circled number in a itemize list. This lack in flexibility could be in some case bothersome. A reasonable solution seems to use the tcolorbox package: after attempts I found that we simply have to add in preamble this

\usepackage{tcolorbox} \newcommand{\ciao}[1]{{\setlength\fboxrule{0pt}\fbox{\tcbox[colframe=black,colback=white,shrink tight,boxrule=0.5pt,extrude by=1mm]{\small #1}}}}

and call in the document the command \ciao when we want a "circled" number (example: \ciao{12} will "circle" the number 12). By the way, the use of fbox in the preamble line is important because without it, rounded box could protrude out of the line on the left or on the right when they are at the margin of the line: this would be very unaesthetic.

Resuming, I see in this solution 3 pros and 1 cons:

  • pros: simple code, good working inside a text too, flexibility (big numbers too & in case we can easily play with borders or colors: see 0.5pt or black&white in the preamble line).
  • cons: we don't have circles but rounded box, but I find this a reasonable compromise.

An example of application of this method is

Quel ramo del lago di Como \ciao{1}, che volge a mezzogiorno, tra due catene \ciao{20} non interrotte di monti, tutto a seni e a golfi, a seconda dello sporgere e del rientrare di quelli, vien, quasi a un tratto, a restringersi, e a prender corso \ciao{252} e figura di fiume, tra un promontorio a destra, e un'ampia costiera dall'altra parte; \ciao{3432} e il ponte che ivi congiunge le due rive, par che renda ancor più sensibile all'occhio questa trasformazione, e segni il punto in cui il lago cessa, e l'Adda ricomincia, per ripigliar poi nome di lago dove le rive, allontanandosi di nuovo, lascian l'acqua distendersi e rallentarsi in nuovi golfi e in nuovi seni.

that gives

enter image description here

please note that numbers doesn't protrude and that the space between lines is always the same: no matter if we have a number or not. In short, this almost circled numbers works very well even if they are inside a text.

2

https://www.ctan.org/pkg/circledtext is another option for you, it's great!

\documentclass{article}
\usepackage{circledtext}
\usepackage{pgffor}
\begin{document}
\begin{center}
  \foreach \x in {1,2,...,10,100,999}
  {
    \circledtext{\x}\,
  }

  \circledtextset{boxcolor=cyan,boxtype=ox,charf=\Large,boxfill = red!20}
  \foreach \x in {1,2,...,10,100,999}
  {
    \circledtext{\x}\,
  }
\end{center}
\end{document}

enter image description here

0
\documentclass{standalone}
\usepackage{pifont}
%%% grab https://ctan.org/tex-archive/fonts/magic
\DeclareFontFamily{U}{magic}{}
\DeclareFontShape{U}{magic}{m}{n}{<-> magic}{}
%\usepackage{relsize}%%% if you wish to adapt to the size of the main text, downscaling by a factor of 2.5 seems just about right.
\begin{document}
%\textsmaller[2.5]{%
  \Pisymbol{magic}{48}
  \Pisymbol{magic}{49}
  \Pisymbol{magic}{50}
  \Pisymbol{magic}{51}
  \Pisymbol{magic}{52}
  \Pisymbol{magic}{53}
  \Pisymbol{magic}{54}
  \Pisymbol{magic}{55}
  \Pisymbol{magic}{56}
  \Pisymbol{magic}{57}
%}
\end{document}

magic standalone output

The borders parts of the circles are slightly cut; otherwise, everything is fine.

If you go with article instead of standalone, you won't even notice:

magic article output

NewTX also provides us with the symbols, but the bounding boxes are even more wrong:

\documentclass{standalone}
\usepackage{newtxtext}
\begin{document}
\textcircled{0}\textcircled{1}\textcircled{2}\textcircled{3}\textcircled{4}\textcircled{5}\textcircled{6}\textcircled{7}\textcircled{8}\textcircled{9}
\end{document}

NewTX standalone

With article instead of standalone, all seems fine again:

NewTX article

0

In MathJax, you can use the enclose macro from the enclose extension. Here's some sample code and its output.

$$\enclose{circle}{1} \enclose{circle}{2} \enclose{circle}{3}$$

enter image description here

Although the OP is using pdfLaTeX, I figure I won't be the only person to ask the same question about MathJax.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .