### Who is online

In total there are 16 users online :: 0 registered, 0 hidden and 16 guests (based on users active over the past 5 minutes)
Most users ever online was 1327 on Tue Nov 05, 2013 7:11 pm

Users browsing this forum: No registered users and 16 guests

## How to draw a circle around text

Add tags LaTeX specific issues not fitting into one of the other forums of this category.

### How to draw a circle around text

Hi

I want to circle some text, is this possible/easy?

Thanks

Lily
lilyo

Posts: 2
Joined: Sat Mar 22nd, 2008

### Re: How to draw a circle around text

There are two possible solutions.

1. The preferable one with pgf/tikZ.
Code: Select all  •  Open in writeLaTeX
\tikz \node[draw,circle]{Text};

This way you can produce directly PS or PDF.
2. The alternative with PSTricks.
Code: Select all  •  Open in writeLaTeX
\pscirclebox{Text}

PDF format only works via LaTeX -> DVI -> PS -> PDF.

DVI viewers may not show the correct output in both cases. For more information refer to the documentations of the packages.

Best regards
ThorstenÂ¹
LaTeX Community Moderator

¹ System: openSUSE 13.1 (Linux 3.11.10), TeX Live 2013 (vanilla), TeXworks 0.5 (r1351)
² Posting stopped indefinitely due to offenses

localghost
Site Moderator

Posts: 9219
Joined: Fri Feb 2nd, 2007
Location: Braunschweig, Germany

### Re: How to draw a circle around text

I need to put circled number as table entries. How can I do it? The following code fails.

Code: Select all  •  Open in writeLaTeX
\documentclass{article}\usepackage{pgf,pgfarrows,pgfnodes,pgfautomata,pgfheaps,pgfshade}\usepackage{tikz}\usepackage{graphicx}\begin{document}\begin{tabular}{ccc}\begin{figure}[!]\tikz \node[draw,circle]{12};\end{figure}&1&2\\1 & 2 &3\end{tabular}\end{document}

The error messege is:
Code: Select all  •  Open in writeLaTeX
! LaTeX Error: Not in outer par mode.See the LaTeX manual or LaTeX Companion for explanation.Type  H <return>  for immediate help. ...                                                                                                l.8 \begin{figure}[!]                     \tikz \node[draw,circle]{12};\end{figure}&1&2\\?
patiobarbecue

Posts: 13
Joined: Tue Oct 27th, 2009

### Re: How to draw a circle around text

Hi,

Don't nest floating environments. Try something like this:

Code: Select all  •  Open in writeLaTeX
\documentclass{article}\usepackage{tikz}\begin{document}\begin{tabular}{ccc}\tikz \node[draw,circle]{12};&1&2\\1 & 2 &3\end{tabular}\end{document}
1,1,2,3,5,8,13,21,34,55,89,144,233,...

gmedina

Posts: 2313
Joined: Wed Jul 11th, 2007
Location: Colombia

### Re: How to draw a circle around text

thanks, it works when I tried it in a single tex file. However it doesn't work in a multiple file document. The \usepackage{tikz} is in the main document, and the \tikz.. is used in a file included in the master file. The error is: undefined control sequence. What's going on here?
patiobarbecue

Posts: 13
Joined: Tue Oct 27th, 2009

### Re: How to draw a circle around text

patiobarbecue wrote:thanks, it works when I tried it in a single tex file. However it doesn't work in a multiple file document. The \usepackage{tikz} is in the main document, and the \tikz.. is used in a file included in the master file. The error is: undefined control sequence. What's going on here?

Let me get my crystal ball; oh, wait, I don't have one! Please provide some complete and minimal code (in the sense of a minimal working example). Without such code, it's really hard to tell.
1,1,2,3,5,8,13,21,34,55,89,144,233,...

gmedina

Posts: 2313
Joined: Wed Jul 11th, 2007
Location: Colombia

### Re: How to draw a circle around text

Sorry for the previous question about multi-file document, which turned out to be a stupid mistake. However this arises as a new concern: the circled number doesn't align with other non-circled numbers in other cells of the tabular. Is there a way to make them all sitting at center of a cell?

Code: Select all  •  Open in writeLaTeX
\documentclass{article}\usepackage{pgf,pgfarrows,pgfnodes,pgfautomata,pgfheaps,pgfshade}\usepackage{tikz}\usepackage{graphicx}\newcommand{\mymk}[1]{\tikz \node[draw,circle, inner sep=0pt, minimum size=7mm]{#1};}\begin{document}\begin{center}\begin{tabular}{|ccccc|c}\hline\mymk{$c_{11}$}&\mymk{$c_{12}$}&\mymk{$c_{13}$}&$\cdots$&$c_{1n}$&$u_1$\\$c_{21}$&$c_{22}$&\mymk{$c_{23}$}&$\cdots$&$c_{2n}$&$u_2$\\$\vdots$&         &            &               &  $\vdots$ & $\vdots$\\$c_{m1}$&$\cdots$&$\cdots$&$\cdots$&\mymk{$c_{mn}$}&$u_2$\\\hline$v_1$&$v_2$       &         &     $\cdots$&$v_n$&\\\end{tabular}\end{center}\end{document}
patiobarbecue

Posts: 13
Joined: Tue Oct 27th, 2009

### Re: How to draw a circle around text

I just found a related post http://www.latex-community.org/forum/viewtopic.php?f=45&t=5678&p=26598&hilit=tabular+vertical#p26598.However does the command really do vertical alignment? Isn't the \centering only adjust horizontal position? What is the \arraybackslash?

Code: Select all  •  Open in writeLaTeX
\begin{longtable}{>{\centering\arraybackslash}m{7cm}m{3cm}m{3cm}}

My experiment is not very satisfactory since I would like to have all array entries aligned.

Code: Select all  •  Open in writeLaTeX
\documentclass{article}\usepackage{pgf,pgfarrows,pgfnodes,pgfautomata,pgfheaps,pgfshade, pgfmath}\usepackage{tikz}\newcommand{\mymk}[1]{\tikz \node[anchor=south west, draw,circle, inner sep=0pt, minimum size=7mm]{#1};}\usepackage{longtable}\usepackage{array}\usepackage{graphicx}\begin{document}%%http://www.latex-community.org/forum/viewtopic.php?f=45&t=5678&p=26598&hilit=tabular+vertical#p26598\begin{center}\begin{longtable}{>{\centering\arraybackslash}m{1cm}m{1cm}m{1cm}m{1cm}m{1cm}m{1cm}}\hline\mymk{$c_{11}$}&\mymk{$c_{12}$}&\mymk{$c_{13}$}&$\cdots$&$c_{1n}$&$u_1$\\$c_{21}$&$c_{22}$&\mymk{$c_{23}$}&$\cdots$&$c_{2n}$&$u_2$\\$\vdots$&         &            &               &  $\vdots$ & $\vdots$\\$c_{m1}$&$\cdots$&$\cdots$&$\cdots$&\mymk{$c_{mn}$}&$u_2$\\\hline$v_1$&$v_2$       &         &     $\cdots$&$v_n$&\\\end{longtable}\end{center}\end{document}
patiobarbecue

Posts: 13
Joined: Tue Oct 27th, 2009

### Re: How to draw a circle around text

patiobarbecue wrote:However does the command really do vertical alignment? Isn't the \centering only adjust horizontal position? What is the \arraybackslash?

The vertical alignment is not due to \centering but to the column declaration m{<length>}. The \centering command (and also \raggedright and \raggedleft) redefines the line changing command \\; the command \arraybackslash restores \\ to its original definition. For further details, please refer to the documentation of the array package.

Take a look at the following modification of your code.

Code: Select all  •  Open in writeLaTeX

Remarks: 1) I used the *{...}{...} construct to simplify the format declaration for the table; refer to the documentation of the array package (link provided above).
2) I used the \ensuremath command provided by the amsmath package.
3) I defined a new command (\mymku) that behaves exactly as \mymk, except that it doesn't draw a circle around its contents.
4) I used the text height option to align the nodes vertically.
5) I deleted the packages that were not relevant for this particular example. Please load them again in your actual code.
1,1,2,3,5,8,13,21,34,55,89,144,233,...

gmedina

Posts: 2313
Joined: Wed Jul 11th, 2007
Location: Colombia

### Re: How to draw a circle around text

Thanks, gmedina! I have been looking for such a beautiful solution for long! I love my table now -:)
patiobarbecue

Posts: 13
Joined: Tue Oct 27th, 2009