LaTeX forum ⇒ GeneralHow to draw a circle around text

LaTeX specific issues not fitting into one of the other forums of this category.
lilyo
Posts: 2
Joined: Sat Mar 22, 2008 6:13 pm

How to draw a circle around text

Postby lilyo » Thu Mar 27, 2008 11:26 pm

Hi

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

Thanks

Lily

Link:
BBcode:
HTML:
Hide post links
Show post links

User avatar
localghost
Site Moderator
Posts: 9206
Joined: Fri Feb 02, 2007 12:06 pm
Location: Braunschweig, Germany

Postby localghost » Thu Mar 27, 2008 11:54 pm

There are two possible solutions.

  1. The preferable one with pgf/tikZ.
    1. \tikz \node[draw,circle]{Text};

    This way you can produce directly PS or PDF.
  2. The alternative with PSTricks.
    1. \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
How to make a "Minimal Example"
Board Rules
Avoidable Mistakes


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

Link:
BBcode:
HTML:
Hide post links
Show post links

patiobarbecue
Posts: 13
Joined: Tue Oct 27, 2009 3:28 pm

Postby patiobarbecue » Fri Feb 05, 2010 3:11 am

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

  1. \documentclass{article}
  2. \usepackage{pgf,pgfarrows,pgfnodes,pgfautomata,pgfheaps,pgfshade}
  3. \usepackage{tikz}
  4. \usepackage{graphicx}
  5. \begin{document}
  6.  
  7. \begin{tabular}{ccc}
  8. \begin{figure}[!]\tikz \node[draw,circle]{12};\end{figure}&1&2\\
  9. 1 & 2 &3
  10. \end{tabular}
  11.  
  12. \end{document}


The error messege is:
  1. ! LaTeX Error: Not in outer par mode.
  2.  
  3. See the LaTeX manual or LaTeX Companion for explanation.
  4. Type H <return> for immediate help.
  5. ...
  6.  
  7. l.8 \begin{figure}[!]
  8. \tikz \node[draw,circle]{12};\end{figure}&1&2\\
  9. ?

Link:
BBcode:
HTML:
Hide post links
Show post links

User avatar
gmedina
Posts: 2313
Joined: Wed Jul 11, 2007 11:45 pm
Location: Colombia

Postby gmedina » Fri Feb 05, 2010 4:33 am

Hi,

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

  1. \documentclass{article}
  2. \usepackage{tikz}
  3.  
  4. \begin{document}
  5.  
  6. \begin{tabular}{ccc}
  7. \tikz \node[draw,circle]{12};&1&2\\
  8. 1 & 2 &3
  9. \end{tabular}
  10.  
  11. \end{document}
1,1,2,3,5,8,13,21,34,55,89,144,233,...

Link:
BBcode:
HTML:
Hide post links
Show post links

patiobarbecue
Posts: 13
Joined: Tue Oct 27, 2009 3:28 pm

Postby patiobarbecue » Fri Feb 05, 2010 5:34 am

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?

Link:
BBcode:
HTML:
Hide post links
Show post links

User avatar
gmedina
Posts: 2313
Joined: Wed Jul 11, 2007 11:45 pm
Location: Colombia

Postby gmedina » Fri Feb 05, 2010 5:48 am

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

Link:
BBcode:
HTML:
Hide post links
Show post links

patiobarbecue
Posts: 13
Joined: Tue Oct 27, 2009 3:28 pm

Postby patiobarbecue » Fri Feb 05, 2010 6:19 am

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?

  1. \documentclass{article}
  2. \usepackage{pgf,pgfarrows,pgfnodes,pgfautomata,pgfheaps,pgfshade}
  3. \usepackage{tikz}
  4. \usepackage{graphicx}
  5. \newcommand{\mymk}[1]{\tikz \node[draw,circle, inner sep=0pt, minimum size=7mm]{#1};}
  6. \begin{document}
  7.  
  8. \begin{center}
  9. \begin{tabular}{|ccccc|c}
  10. \hline
  11. \mymk{$c_{11}$}&\mymk{$c_{12}$}&\mymk{$c_{13}$}&$\cdots$&$c_{1n}$&$u_1$\\
  12. $c_{21}$&$c_{22}$&\mymk{$c_{23}$}&$\cdots$&$c_{2n}$&$u_2$\\
  13. $\vdots$& & & & $\vdots$ & $\vdots$\\
  14. $c_{m1}$&$\cdots$&$\cdots$&$\cdots$&\mymk{$c_{mn}$}&$u_2$\\
  15. \hline
  16. $v_1$&$v_2$ & & $\cdots$&$v_n$&
  17. \\
  18. \end{tabular}
  19. \end{center}
  20.  
  21.  
  22. \end{document}

Link:
BBcode:
HTML:
Hide post links
Show post links

patiobarbecue
Posts: 13
Joined: Tue Oct 27, 2009 3:28 pm

Postby patiobarbecue » Fri Feb 05, 2010 7:35 am

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?

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

  1. \documentclass{article}
  2. \usepackage{pgf,pgfarrows,pgfnodes,pgfautomata,pgfheaps,pgfshade, pgfmath}
  3. \usepackage{tikz}
  4.  
  5. \newcommand{\mymk}[1]{\tikz \node[anchor=south west, draw,circle, inner sep=0pt, minimum size=7mm]{#1};}
  6.  
  7. \usepackage{longtable}
  8. \usepackage{array}
  9. \usepackage{graphicx}
  10.  
  11.  
  12. \begin{document}
  13.  
  14. %%http://www.latex-community.org/forum/viewtopic.php?f=45&t=5678&p=26598&hilit=tabular+vertical#p26598
  15. \begin{center}
  16. \begin{longtable}{>{\centering\arraybackslash}m{1cm}m{1cm}m{1cm}m{1cm}m{1cm}m{1cm}}
  17. \hline
  18. \mymk{$c_{11}$}&\mymk{$c_{12}$}&\mymk{$c_{13}$}&$\cdots$&$c_{1n}$&$u_1$\\
  19. $c_{21}$&$c_{22}$&\mymk{$c_{23}$}&$\cdots$&$c_{2n}$&$u_2$\\
  20. $\vdots$& & & & $\vdots$ & $\vdots$\\
  21. $c_{m1}$&$\cdots$&$\cdots$&$\cdots$&\mymk{$c_{mn}$}&$u_2$\\
  22. \hline
  23. $v_1$&$v_2$ & & $\cdots$&$v_n$&
  24. \\
  25. \end{longtable}
  26. \end{center}
  27.  
  28. \end{document}

Link:
BBcode:
HTML:
Hide post links
Show post links

User avatar
gmedina
Posts: 2313
Joined: Wed Jul 11, 2007 11:45 pm
Location: Colombia

Postby gmedina » Fri Feb 05, 2010 3:39 pm

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.

  1. \documentclass{article}
  2. \usepackage{amsmath}
  3. \usepackage{tikz}
  4. \usepackage{longtable}
  5. \usepackage{array}
  6.  
  7. % nodes with circle
  8. \newcommand{\mymk}[1]{%
  9. \tikz \node[anchor=south west, draw,circle, inner sep=0pt, minimum size=7mm,
  10. text height=2mm]{\ensuremath{#1}} ;}
  11. % nodes without circle
  12. \newcommand{\mymku}[1]{%
  13. \tikz \node[anchor=south west, circle, inner sep=0pt, minimum size=7mm,
  14. text height=2mm]{\ensuremath{#1}} ;}
  15.  
  16. \begin{document}
  17.  
  18. \begin{center}
  19. \setlength\extrarowheight{3mm}
  20. \begin{longtable}{*{6}{>{\centering\arraybackslash}m{1cm}}}
  21. \hline
  22. \mymk{c_{11}} & \mymk{c_{12}} & \mymk{c_{13}} & \mymku{\cdots} &
  23. \mymku{c_{1n}} & \mymku{u_1}\\
  24. \mymku{c_{21}} & \mymku{c_{22}} & \mymk{c_{23}} & \mymku{\cdots} &
  25. \mymku{c_{2n}} & \mymku{u_2}\\
  26. \mymku{\vdots} & & & & \mymku{\vdots} & \mymku{\vdots}\\
  27. \mymku{c_{m1}} & \mymku{\cdots} & \mymku{\cdots} & \mymku{\cdots} &
  28. \mymk{c_{mn}} & \mymku{u_2}\\
  29. \hline
  30. \mymku{v_1} & \mymku{v_2} & & \mymku{\cdots} & \mymku{v_n} &\\
  31. \end{longtable}
  32. \end{center}
  33.  
  34. \end{document}


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

Link:
BBcode:
HTML:
Hide post links
Show post links

patiobarbecue
Posts: 13
Joined: Tue Oct 27, 2009 3:28 pm

Postby patiobarbecue » Fri Feb 05, 2010 5:18 pm

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

Link:
BBcode:
HTML:
Hide post links
Show post links


Return to “General”

Who is online

Users browsing this forum: Yahoo [Bot] and 8 guests