Hi
I want to circle some text, is this possible/easy?
Thanks
Lily
LaTeX forum ⇒ General ⇒ How to draw a circle around text
- localghost
- Site Moderator
- Posts: 9202
- Joined: Fri Feb 02, 2007 12:06 pm
How to draw a circle around text
There are two possible solutions.
DVI viewers may not show the correct output in both cases. For more information refer to the documentations of the packages.
Best regards
Thorsten¹
- The preferable one with pgf/tikZ.
\tikz \node[draw,circle]{Text};
This way you can produce directly PS or PDF. - The alternative with PSTricks.
\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 42.2 (Linux 4.4.52), TeX Live 2016 (vanilla), TeXworks 0.6.1
How to make a "Minimal Example"
Board Rules
Avoidable Mistakes
¹ System: openSUSE 42.2 (Linux 4.4.52), TeX Live 2016 (vanilla), TeXworks 0.6.1
-
- Posts: 13
- Joined: Tue Oct 27, 2009 3:28 pm
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.
The error messege is:
\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:
! 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\\ ?
How to draw a circle around text
Hi,
Don't nest floating environments. Try something like this:
Don't nest floating environments. Try something like this:
\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,...
-
- Posts: 13
- Joined: Tue Oct 27, 2009 3:28 pm
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?
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,...
-
- Posts: 13
- Joined: Tue Oct 27, 2009 3:28 pm
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?
\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}
-
- Posts: 13
- Joined: Tue Oct 27, 2009 3:28 pm
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?
My experiment is not very satisfactory since I would like to have all array entries aligned.
\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.
\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}
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.
\documentclass{article} \usepackage{amsmath} \usepackage{tikz} \usepackage{longtable} \usepackage{array} % nodes with circle \newcommand{\mymk}[1]{% \tikz \node[anchor=south west, draw,circle, inner sep=0pt, minimum size=7mm, text height=2mm]{\ensuremath{#1}} ;} % nodes without circle \newcommand{\mymku}[1]{% \tikz \node[anchor=south west, circle, inner sep=0pt, minimum size=7mm, text height=2mm]{\ensuremath{#1}} ;} \begin{document} \begin{center} \setlength\extrarowheight{3mm} \begin{longtable}{*{6}{>{\centering\arraybackslash}m{1cm}}} \hline \mymk{c_{11}} & \mymk{c_{12}} & \mymk{c_{13}} & \mymku{\cdots} & \mymku{c_{1n}} & \mymku{u_1}\\ \mymku{c_{21}} & \mymku{c_{22}} & \mymk{c_{23}} & \mymku{\cdots} & \mymku{c_{2n}} & \mymku{u_2}\\ \mymku{\vdots} & & & & \mymku{\vdots} & \mymku{\vdots}\\ \mymku{c_{m1}} & \mymku{\cdots} & \mymku{\cdots} & \mymku{\cdots} & \mymk{c_{mn}} & \mymku{u_2}\\ \hline \mymku{v_1} & \mymku{v_2} & & \mymku{\cdots} & \mymku{v_n} &\\ \end{longtable} \end{center} \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,...
-
- Posts: 13
- Joined: Tue Oct 27, 2009 3:28 pm
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 -:)
Who is online
Users browsing this forum: No registered users and 11 guests