General ⇒ How to draw a circle around text
How to draw a circle around text
I want to circle some text, is this possible/easy?
Thanks
Lily
NEW: TikZ book now 40% off at Amazon.com for a short time.
And: Currently, Packt sells ebooks for $4.99 each if you buy 5 of their over 1000 ebooks. If you choose only a single one, $9.99. How about combining 3 LaTeX books with Python, gnuplot, mathplotlib, Matlab, ChatGPT or other AI books? Epub and PDF. Bundle (3 books, add more for higher discount): https://packt.link/MDH5p
- localghost
- Site Moderator
- Posts: 9202
- Joined: Fri Feb 02, 2007 12:06 pm
How to draw a circle around text
- The preferable one with pgf/tikZ.
This way you can produce directly PS or PDF.
Code: Select all
\tikz \node[draw,circle]{Text};
- The alternative with PSTricks.
PDF format only works via LaTeX -> DVI -> PS -> PDF.
Code: Select all
\pscirclebox{Text}
Best regards
Thorsten¹
Board Rules
Avoidable Mistakes
¹ System: TeX Live 2025 (vanilla), TeXworks 0.6.10
-
- Posts: 13
- Joined: Tue Oct 27, 2009 3:28 pm
How to draw a circle around text
Code: Select all
\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}
Code: Select all
! 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
Don't nest floating environments. Try something like this:
Code: Select all
\documentclass{article}
\usepackage{tikz}
\begin{document}
\begin{tabular}{ccc}
\tikz \node[draw,circle]{12};&1&2\\
1 & 2 &3
\end{tabular}
\end{document}
-
- Posts: 13
- Joined: Tue Oct 27, 2009 3:28 pm
Re: How to draw a circle around text
How to draw a circle around text
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.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?
-
- Posts: 13
- Joined: Tue Oct 27, 2009 3:28 pm
How to draw a circle around text
Code: Select all
\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
Code: Select all
\begin{longtable}{>{\centering\arraybackslash}m{7cm}m{3cm}m{3cm}}
Code: Select all
\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
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.patiobarbecue wrote:However does the command really do vertical alignment? Isn't the \centering only adjust horizontal position? What is the \arraybackslash?
Take a look at the following modification of your code.
Code: Select all
\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}
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.
-
- Posts: 13
- Joined: Tue Oct 27, 2009 3:28 pm