Featured Book

LaTeX Beginners Guide

Who is online

In total there are 20 users online :: 1 registered, 0 hidden and 19 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: Google [Bot] and 19 guests

Partner Sites

TeXwelt - Fragen und Antworten goLaTeX
TeXblog
TeXnicCenter
TeXample

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

Postby lilyo on Thu Mar 27th, 2008

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

Postby localghost on Thu Mar 27th, 2008

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
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
User avatar
localghost
Site Moderator
 
Posts: 9219
Joined: Fri Feb 2nd, 2007
Location: Braunschweig, Germany

Re: How to draw a circle around text

Postby patiobarbecue on Fri Feb 5th, 2010

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

Postby gmedina on Fri Feb 5th, 2010

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,...
User avatar
gmedina
 
Posts: 2313
Joined: Wed Jul 11th, 2007
Location: Colombia

Re: How to draw a circle around text

Postby patiobarbecue on Fri Feb 5th, 2010

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

Postby gmedina on Fri Feb 5th, 2010

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,...
User avatar
gmedina
 
Posts: 2313
Joined: Wed Jul 11th, 2007
Location: Colombia

Re: How to draw a circle around text

Postby patiobarbecue on Fri Feb 5th, 2010

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

Postby patiobarbecue on Fri Feb 5th, 2010

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

Postby gmedina on Fri Feb 5th, 2010

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
\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,...
User avatar
gmedina
 
Posts: 2313
Joined: Wed Jul 11th, 2007
Location: Colombia

Re: How to draw a circle around text

Postby patiobarbecue on Fri Feb 5th, 2010

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


Return to General

Who is online

Users browsing this forum: Google [Bot] and 19 guests