Graphics, Figures & Tables ⇒ Creating boxes and circles inside a table
-
- Posts: 97
- Joined: Fri Sep 04, 2009 4:56 pm
Creating boxes and circles inside a table
Hello friends,
I need to create a special type of table in which, a circle or square or a circle and square should be placed. And also the item such as "20" or "-5" should appear inside the corresponding circle or squares.
I know its difficult to imagine, hence i have attached the pdf file of it, please go through it and let me know the code, how i can proceed to get the table done..
Thanking you in advance,
Regards,
Muthu
I need to create a special type of table in which, a circle or square or a circle and square should be placed. And also the item such as "20" or "-5" should appear inside the corresponding circle or squares.
I know its difficult to imagine, hence i have attached the pdf file of it, please go through it and let me know the code, how i can proceed to get the table done..
Thanking you in advance,
Regards,
Muthu
- Attachments
-
- muthu.pdf
- (50.91 KiB) Downloaded 380 times
NEW: TikZ book now 40% off at Amazon.com for a short time.

- localghost
- Site Moderator
- Posts: 9202
- Joined: Fri Feb 02, 2007 12:06 pm
Creating boxes and circles inside a table
The Forum Search yields several result at least for circled text.
Best regards
Thorsten
- View topic: How to draw a circle around text
- View topic: Circle around letter
- View topic: circle around letters
Best regards
Thorsten
How to make a "Minimal Example"
Board Rules
Avoidable Mistakes
¹ System: TeX Live 2025 (vanilla), TeXworks 0.6.10
Board Rules
Avoidable Mistakes
¹ System: TeX Live 2025 (vanilla), TeXworks 0.6.10
-
- Posts: 97
- Joined: Fri Sep 04, 2009 4:56 pm
Creating boxes and circles inside a table
Hello Thorsten,
Thanks for your reply...
With that, i was now able to create tables with circles..
But the circle is not correctly placed in my table.. I don't know where i am going wrong.. The table is not looking good..
Please let me know the correction.
Thank you in advance. I have attached the pdf.
Regards,
Muthu
Thanks for your reply...
With that, i was now able to create tables with circles..
But the circle is not correctly placed in my table.. I don't know where i am going wrong.. The table is not looking good..
Please let me know the correction.
Code: Select all
\documentclass[b5paper,10.5pt]{book}
\usepackage{array,amsmath}
\usepackage{tikz-inet,pgf}
\usetikzlibrary{matrix}
\usepackage[centering,
headheight=14pt,
headsep=10pt,
includehead,
papersize={18cm,24cm},
text={15.25cm,19.2cm},
dvips=false,
pdftex=false,
vtex=false
]{geometry}
\usepackage[cam,a4,center,dvips]{crop}
\usepackage{graphicx,colortbl}
\usepackage{booktabs,multirow}
\usepackage{longtable}
% 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,draw, rectangle, inner sep=0pt, minimum size=7mm,
text height=2mm]{\ensuremath{#1}} ;}
\newcommand{\mymkm}[1]{%
\tikz \node[anchor=south west,draw, rectangle, inner sep=0pt, minimum size=7mm,
text height=7.2mm]{\ensuremath{#1}} ;}
\newcommand{\none}[1]{%
\tikz \node[anchor=south west, rectangle, inner sep=0pt, minimum size=7mm,
text height=2mm]{\ensuremath{#1}} ;}
\begin{document}
\begin{center}
\setlength\extrarowheight{3mm}
\begin{longtable}{>{\centering\arraybackslash}m{2cm}>{\centering\arraybackslash}m{1cm} >{\centering\arraybackslash}m{1cm}>{\centering\arraybackslash}m{1cm} }
& & \multicolumn{2}{c}{Player B}\\
& & $B_1$ & $B_2$\\ \cline{2-4}
\multirow{3}*{Player A} & \multicolumn{1}{|c|}{\none{A_1}} & \multicolumn{1}{c|}{\mymk{20}} & \multicolumn{1}{c|}{\mymku{80}}\\ \cline{2-4}
& \multicolumn{1}{|c|}{\none{A_2}} & \multicolumn{1}{c|}{\none{40}} & \multicolumn{1}{c|}{\mymk{30}}\\ \cline{2-4}
& \multicolumn{1}{|c|}{\none{A_3}} & \multicolumn{1}{c|}{\mymk{\mymkm{50}}} & \multicolumn{1}{c|}{\none{60}}\\ \cline{2-4}
& \multicolumn{3}{c}{Value of game V=50}\\
\end{longtable}
\end{center}
\end{document}
Regards,
Muthu
- Attachments
-
- tab-circ.pdf
- (36.34 KiB) Downloaded 603 times
Creating boxes and circles inside a table
Hi Muthu,
try something like this:
By the way, 10.5pt is not a valid class option.
try something like this:
Code: Select all
\documentclass[b5paper]{book}
\usepackage{array,amsmath}
\usepackage{tikz-inet,pgf}
\usetikzlibrary{matrix,calc}
\usepackage[centering,
headheight=14pt,
headsep=10pt,
includehead,
papersize={18cm,24cm},
text={15.25cm,19.2cm},
dvips=false,
pdftex=false,
vtex=false
]{geometry}
\usepackage[cam,a4,center]{crop}
\usepackage{graphicx,colortbl}
\usepackage{booktabs,multirow}
\usepackage{longtable}
% 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 with rectangle
\newcommand{\mymku}[1]{%
\tikz \node[draw, rectangle, inner sep=0pt, minimum size=7mm,
text height=2mm]{\ensuremath{#1}} ;}
% nodes with circle and rectangle
\newcommand{\mymkcr}[1]{%
\tikz \draw node (a) [draw,circle,minimum size=7mm,after node path={(\tikzlastnode)
($(a.south west)+(-3pt,-3pt)$) rectangle ($(a.north east)+(3pt,3pt)$)}]{#1};}
% nodes without border
\newcommand{\none}[1]{%
\tikz \node[anchor=south west, rectangle, inner sep=0pt, minimum size=7mm,
text height=2mm]{\ensuremath{#1}} ;}
\newcolumntype{A}[1]{>{\centering\arraybackslash}m{#1}}
\newcommand\ventry{\multicolumn{1}{c}{}}
\begin{document}
\begin{center}
\setlength\extrarowheight{3.6mm}
\begin{longtable}{A{2cm}|A{1cm}|A{1cm}|A{1cm}|}
\ventry & \ventry & \multicolumn{2}{c}{Player B}\\
\ventry & \ventry & \multicolumn{1}{c}{$B_1$} & \multicolumn{1}{c}{$B_2$}\\
\cline{2-4}
\multirow{3}*{Player A} & \none{A_1} & \mymk{20} & \mymku{80}\\
\cline{2-4}
& \none{A_2} & \none{40} & \mymk{30}\\
\cline{2-4}
& \none{A_3} & \mymkcr{50} & \none{60}\\
\cline{2-4}
\ventry & \multicolumn{3}{c}{Value of game V=50}
\end{longtable}
\end{center}
\end{document}
1,1,2,3,5,8,13,21,34,55,89,144,233,...
-
- Posts: 97
- Joined: Fri Sep 04, 2009 4:56 pm
Re: Creating boxes and circles inside a table
Hello gmedina,
Thanks for your perfect solution. Now my table is looking good.
I wonder we can encircle a particular row in the table. Please do help me in this regard.
I am herewith attaching the table for your reference.
Regards,
Muthu
Thanks for your perfect solution. Now my table is looking good.
I wonder we can encircle a particular row in the table. Please do help me in this regard.
I am herewith attaching the table for your reference.
Regards,
Muthu
- Attachments
-
- k.pdf
- (19.88 KiB) Downloaded 492 times
Creating boxes and circles inside a table
One possibility would be to use the hhline package (however you cannot obtain rounded corners with this package, so the row will be enclosed by a rectangle).
Another option is to use PGF/TikZ; here's an example:
Another option is to use PGF/TikZ; here's an example:
Code: Select all
\documentclass{book}
\usepackage{tikz-inet}
\usetikzlibrary{matrix,fit,calc}
\begin{document}
\begin{tikzpicture}
\matrix (magic) [%
matrix of nodes,row sep=1mm,
text width=10mm,text height=1mm,
text badly centered
]
{%
\ & I & II & III & IV & V\\
I & 3 & 5 & 4 & 9 & 3\\
II & 5 & 6 & 9 & 7 & 8\\
III & 8 & 7 & 8 & 8 & 9\\
IV & 4 & 4 & 8 & 5 & 3\\
};
% horizontal lines of the table
\draw (magic-1-2.north west) -- (magic-1-6.north east);
\foreach \i in {2,3,4,5}
\draw (magic-\i-1.north west) -- (magic-\i-6.north east);
\draw (magic-5-1.south west) -- (magic-5-6.south east);
% vertical lines of the table
\draw (magic-2-1.north west) -- (magic-5-1.south west);
\foreach \j in {2,3,4,5,6}
\draw (magic-1-\j.north west) -- (magic-5-\j.south west);
\draw (magic-1-6.north east) -- (magic-5-6.south east);
% the rounded rectangle for a row
\draw [rounded corners=2pt,thin]
($(magic-5-2.north west)+(2pt,-2pt)$) rectangle ($(magic-5-6.south east)+(-2pt,2pt)$);
% some labels
\node at ($(magic.north)+(18pt,5pt)$) {B};
\node at ($(magic.west)+(-8pt,-10pt)$) {A};
\end{tikzpicture}
\end{document}
1,1,2,3,5,8,13,21,34,55,89,144,233,...