7

Based on Good way to make \textcircled numbers?, is there a simple way to make the circles look exactly the same for numbers and all letters (i.e. size and placement)?

When one inserts an a in the circle, the node is drawn slightly lower than the node for a number.

\documentclass{article}

\usepackage{tikz}
\newcommand*\circled[1]{\tikz[baseline=(char.base)]{
    \node[shape=circle, draw, inner sep=1pt, 
        minimum height=12pt] (char) {#1};}}

\begin{document}
This is \circled{a} \circled{1} balloon.
\end{document}

enter image description here

EDIT

Based on the answer by @koleygr and the post circled letters: same size as uncircled letters, I find this solution the most pleasing and versatile:

\newcommand*{\circled}[2][]{\tikz[baseline=(C.base)]{
    \node[inner sep=0pt] (C) {\vphantom{1g}#2};
    \node[draw, circle, inner sep=3pt, yshift=1pt] 
        at (C.center) {\vphantom{1g}};}}

enter image description here

  • 4
    i'd try putting a \strut in with the letter or digit to guarantee that that's encircled always has the same height and depth. (not tried; the default \strut may be a bit large, so an alternative could be \vphantom{Xy}.) – barbara beeton Sep 19 '17 at 19:56
  • I edited my answer... You can write and select yours or make a combination of all and write an answer that contain all you need. It is ok to select your answer if it works better for your request and also it is better than letting selected an answer that doesn't really solves all parts of the problem. – koleygr Sep 19 '17 at 20:48
9

Edit after accepted:

\documentclass{article}

\makeatletter
\usepackage{tikz}
\usetikzlibrary{calc}
\newcommand*\circled[1]{\tikz[baseline=(char.base)]{
    \node[shape=circle, draw, inner sep=1pt, 
        minimum height={\f@size*1.6},] (char) {\vphantom{WAH1g}#1};}}
\makeatother

\begin{document}
This is \circled{a} \circled{1} balloon.

\noindent\foreach \letter in {A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,V,U,W,X,Y,Z,a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z,1,2,3,4,5,6,7,8,9,0,.,/}
{%
\circled{\letter}\space%
}
\end{document}

Output:

enter image description here

Not really perfect because of different base on chars (but it is better from the bellow answer)

Checking the same code in the document environment above with below definition of circled:

enter image description here

As you can see with previous (below) code the sizes change between small and capital letters.

Old answer:

A \vphantom in your definition will help:

\documentclass{article}

\usepackage{tikz}
\newcommand*\circled[1]{\tikz[baseline=(char.base)]{
    \node[shape=circle, draw, inner sep=1pt, 
        minimum height=12pt] (char) {\vphantom{1g}#1};}}

\begin{document}
This is \circled{a} \circled{1} balloon.
\end{document}

Output:

enter image description here

  • it appears that you're using a "one" in the \vphantom instead of a letter. in some fonts (including, i believe, computer modern), the digits are not as tall as the tallest letters. so using an "ell" instead of a "one" would shift the circle just slightly higher, but not so high as to adversely affect the letters with descenders. – barbara beeton Sep 20 '17 at 0:28
  • Thanks for the comment @barbarabeeton... But I think the 1.6\f@size will take care of most cases. I think 1.75 or 1.8 would be better (as you can see in my output where capitals are in greater circle). Do you thing I have to place an H (or something) there instead of 1? I just kept "1" from my previous answer that is based on OP's question... But of course I can change it. I think I have to add that the taller letter has to be added there for different languages... What do you think? – koleygr Sep 20 '17 at 0:35
  • @barbarabeeton I added some letters that I suppose that have enough height. Thanks again – koleygr Sep 20 '17 at 2:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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