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 used the statement

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

to draw some circled integers.

Ex.

\circled{$X'$} \circled{$1'$} \circled{$1$} \circled{$2'$} \circled{$2$} 

But these are not same size.

How can I fix it?

output

share|improve this question
1  
Give a minimum size key to the node. A size of 2em works for your case. –  JLDiaz Sep 2 at 8:27

7 Answers 7

There are subtle points relating to the basline aligment.

In the answer by moospit, no baseline is specified for the circled nodes, so they will be using the bottom of the circle as alignment. This produces bad results when used with other characters in the same line:

\renewcommand*\circled[1]{\tikz{\node[shape=circle,draw,minimum size=2.2em, label={center:#1}] (char) {};}}

\leavevmode\rlap{\hbox to 8cm{\hrulefill}} % This is to draw the baseline of the line
\circled{$X'$} \circled{$1'$} \circled{$1$} \circled{$2'$} \circled{$2$} \circled{p} p

Bad result

If we add a baseline key to the \tikz command it still doesn't work right, because the nodes have no real content because it is typeset via label, and thus the baseline of each node is through its center:

\renewcommand*\circled[1]{\tikz[baseline=(char.base)]{\node[shape=circle,draw,minimum size=2.2em, label={center:#1}] (char) {};}}

\leavevmode\rlap{\hbox to 8cm{\hrulefill}}
\circled{$X'$} \circled{$1'$} \circled{$1$} \circled{$2'$} \circled{$2$} \circled{p} p

Still bad result

In a comment, I proposed to simply add a minimum size key to the node. This is basically what Harish Kumar does in its answer. This approach correctly aligns the baseline of the text insde each node with the baseline of the line. However, for the node containing only "p", the circle around it is not properly placed:

\newcommand*\circled[1]{\tikz[baseline=(char.base)]{
\node[anchor=text, shape=circle,draw, inner sep=0pt, minimum size=2.2em] (char) {#1};}}

\leavevmode\rlap{\hbox to 8cm{\hrulefill}}
\circled{$X'$} \circled{$1'$} \circled{$1$} \circled{$2'$} \circled{$2$} \circled{p} p

Almost!

This is because that node has descenders, but not ascenders. This can be fixed if each node includes a \strut which is an invisible line of the appropiate height. The \strut can be included as part of the \circled command:

\newcommand*\circled[1]{\tikz[baseline=(char.base)]{
\node[anchor=text, shape=circle,draw, inner sep=0pt, minimum size=2.2em] (char) {#1\strut};}}

\leavevmode\rlap{\hbox to 8cm{\hrulefill}}
\circled{$X'$} \circled{$1'$} \circled{$1$} \circled{$2'$} \circled{$2$} \circled{p} p

Result

share|improve this answer

You can use the node's label option and center its position. You only have to adjust the inner and outer seps of the nodes to your needings:

\newcommand*\circled[1]{\tikz{\node[shape=circle,draw,inner sep=8pt, label={center:#1}] (char) {};}}
\circled{$X'$} \circled{$1'$} \circled{$1$} \circled{$2'$} \circled{$2$} 

This gives you:

enter image description here

share|improve this answer
    
Sorry, it is too big. –  Alperin Sep 2 at 10:45
1  
You can make it smaller by adjusting your font-size, the inner sep, etc. Are the circles too big, the font? –  moospit Sep 2 at 10:51

For your tikz code, as Harish Kumr says, you need to set a minimum width -- for the characters that you are using 2em seems about right.

If you only want to circle the numbers from 1-10 then a better option is to use the pifont package:

enter image description here

Here is a macro for producing the entries in the first column, for example:

\newcommand\Circnum[1]{%
   \ifcase#1\relax#1\or\ding{172}\or\ding{173}\or\ding{174}
   \or\ding{175}\or\ding{176}\or\ding{177}\or\ding{178}
   \or\ding{179}\or\ding{180}\or\ding{181}
   \or #1\typeout{!! #1 is too big to circle!}
   \fi
}
\Circnum0
\Circnum1
\Circnum2
\Circnum3
\Circnum4
\Circnum5
\Circnum6
\Circnum7
\Circnum8
\Circnum9
\Circnum{10}
share|improve this answer

The simplest code with PSTricks just for fun.

\documentclass[preview,border=12pt,12pt,varwidth]{standalone}
\usepackage{pst-node}
\psset{radius=12pt}
\begin{document}
\begin{enumerate}
\foreach \i in {1,...,20}{\item \Circlenode{node\i}{\i}}
\end{enumerate}
\end{document}

enter image description here

share|improve this answer

Add minimum width=2em to the options as in

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

Further, official tikz way of aligning descenders is to use text depth. Use text depth=0.55ex, and compare with that of JLDiaz.

\documentclass{article}
\usepackage{tikz}
\newcommand*\circled[1]{\tikz[baseline=(char.base)]{
\node[shape=circle,draw,inner sep=0pt,minimum width=2em, text depth=0.55ex] (char) {#1};}
}
\begin{document}
   \circled{$X'$} \circled{$1'$} \circled{$1$} \circled{$2'$} \circled{$2$}

   \leavevmode\rlap{\hbox to 8cm{\hrulefill}}
\circled{$X'$} \circled{$1'$} \circled{$1$} \circled{$2'$} \circled{$2$} \circled{p} p
\end{document}

enter image description here

share|improve this answer
1  
You can use sharelatex. –  In PSTricks we trust Sep 2 at 8:26
    
@cyanide-basedfood Actually the problem was the internet. And I posted my earlier answer using my phone, for the first time. –  Harish Kumar Sep 2 at 12:50
    
I see.......... –  In PSTricks we trust Sep 2 at 13:54

A PSTricks solutoin:

\documentclass{article}

\usepackage{pstricks}

\def\Circle(#1,#2)#3{
  \pscircle(#1,#2){0.6}
  \rput(#1,#2){#3}
}

\begin{document}

\begin{pspicture}(6.1,2)
  \Circle(1.0,1){$a+b$}
  \Circle(2.5,1){$f(x)$}
  \Circle(4.0,1){$\displaystyle\int$}
  \Circle(5.5,1){$\nabla$}
\end{pspicture}

\end{document}

output1

With numbers:

\documentclass{article}

\usepackage{pstricks}
\usepackage{multido}

\def\Circle(#1,#2)#3{
  \pscircle(#1,#2){0.4}
  \rput(#1,#2){#3}
}

\begin{document}

\begin{pspicture}(5.8,5.8)
  \multido{\iA = 1+1, \rA = 0.4+1.0}{6}{
    \multido{\iB = \iA+6, \rB = 0.4+1.0}{6}{\Circle(\rA,\rB){$\iB$}}}
\end{pspicture}

\end{document}

output2

share|improve this answer

Just use unicode! It works only for numbers, though.

①②⑪⑫

share|improve this answer
2  
They're not the same size though, unfortunately. –  Jake Sep 2 at 8:24
    
Oh, hang on, on my phone they are. Seems to be font dependent. –  Jake Sep 2 at 9:33

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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