6

So I have two questions. First, how could I create the following image in TikZ? Secondly, what resources could I use to learn the TikZ to make this on my own and also how can I understand your code (if you could explain it that would be so much appreciated :) ) enter image description here

Also how do I input an image into this. I tried and it said it was too big but this doesn't make sense as it's a simple image of a piece of graph paper. It also said failed when I tried to insert the imgur link into the box.

Any help appreciated thanks so much!

4

7 Answers 7

9

For the first answer, the TikZ documentation could be a good starting point, specially the Tutorials section. The link in the comments provides a lot of interesting resources too. And there are lots of examples across this site, varying from the very simple to the very difficult.

The second: the picture. You can do it with this simple code:

\documentclass[border=2mm,tikz]{standalone}

\begin{document}
\begin{tikzpicture}
\def\R{3}   % Table radius
\def\r{0.5} % Seat radius
% Title
\node at (0,\R+1) {\Large Seats in a round table};
% Table
\draw[thick,fill=brown!30] (0,0) circle (\R);
% Seats (change the number 180 to rotate the seats)
\foreach\i in {1,...,12}  
  \draw[fill=white] (180-30*\i:\R) circle (\r) node {$\i$};
% Center (comment it or remove it if you don't want the center shown)
\fill (0,0) circle (0.5mm);
\end{tikzpicture}
\end{document}

I think that it's self-explanatory but just in case:

  • I made two variables \R and \r, for the radii. This way if you want to change them you don't need to look for then across all the code (not much in this case, but sometimes could be longer).
  • The \foreach statement repeats the next instruction as its name suggests, for each value of the variable \i in the range (1,...,12). So it draws 12 circles at the polar points which angle is function of \i: 180-30*\i (if you change the value 180 for another angle you can rotate the seats). As it is, the angles will be
180-30*1=150,  180-30*2=120,  ...  ,  180-30*12=-180

And finally this is the table: enter image description here

7
  • You're amazing thanks so must!
    – jackson
    Nov 6, 2021 at 12:57
  • What does this line do: \documentclass[border=2mm,tikz]{standalone}
    – jackson
    Nov 6, 2021 at 12:57
  • Also, how could I copy the image from Overleaf?
    – jackson
    Nov 6, 2021 at 13:01
  • @jackson, the line loads a class of document: standalone (useful for examples of images like this), loads also TizZ package and sets a border around the picture of 2mm. Take a look at the package documentation here: ctan.org/pkg/standalone Nov 6, 2021 at 13:22
  • For the other question, I've never used Overleaf... Nov 6, 2021 at 13:24
4

Just for fun one integration of Juan code:

\documentclass[border=2mm,tikz]{standalone}

\begin{document}
    \begin{tikzpicture}
        \def\R{3}   % Table radius
        \def\r{0.6} % Seat radius
        % Title
        \node at (0,\R+1) {\Large Seats in a round table};
        % Table
        \draw[thick,fill=brown!30] (0,0) circle (\R);
        % Seats (change the number 180 to rotate the seats)
        \foreach\i in {1,...,12}  
        \draw[fill=white] (180-30*\i:\R) circle (\r) node {$\i$};
        % Center (comment it or remove it if you don't want the center shown)
        \fill[green] (0,0) circle (2*\r);
        \draw[-latex] (.4,0) arc (0:120:.4);
        \fill (0,0) circle (0.5mm);
        \foreach\i in {1,...,6}  
        \draw[fill=cyan] (180-60*\i:.9) circle (.2) node {};
    \end{tikzpicture}
\end{document}

The result:

enter image description here

2
  • Really cool! Where do you copy the image from?
    – jackson
    Nov 7, 2021 at 3:33
  • @jackson From a real table in a restaurant. Nov 7, 2021 at 4:00
4

Lets ad my two cents :-)

Q: How to learn to create this?

A: Simple. Learn by doing! For example:

  • Use some introductory text about TikZ, for example A very minimal introduction to TikZ∗ and rewrite all examples described in it.
  • After that try to modified those examples (change thickness, color, arrow heads of lines, change size of nodes, type of nodes shapes, their fill color, etc.). If for this is not sufficient information in introductory text, look in "TikZ and PGF manual" for further information or ask here.
  • Before ask a question here, search a site for similar questions. Here is high probability, that from hundreds of questions tagged by "tikz-pgf" some of the are very similar.
  • Try to write MWE (Minimal Working Example), a small but complete document, which reproduce your problem. Now, after three your question in style "do-this-instead-of-me", next question will be probably closed (and unanswered) as Needs details or clarity

An example of Learning by doing:

Let see how I learn to draw your sketch for me on a new way:

  • First, I check all answer on your question and observe that answer of @AndréC shows a way, about which I wasn't aware so far.
  • Second, I look into "TikZ and PGF manual" (it is part of your tikz package installation or you can find it on CTAN by googling). In the section "48.3 Nodes on a Chain", page 603 is described example, which is shown in his answer.
  • Third, I try modified it so, that result will reproduce your sketch and by this learn how to use showed idea. In this I look into other answer, if there is something helpful for my desired modification ...

Result of my learning is:

%%%%    chain-nodes-in-circle                       2021.11.07  %
%---------------------------------------------------------------%
%   modified answer of @AndréC on:                              %
%   https://tex.stackexchange.com/questions/621512/             %
%           how-to-create-this-using-tikz-and-how-i-could-      %
%           learn-to-create-this                                %
%---------------------------------------------------------------%
%   his answer is copy of example in TikZ & PGF manual          % 
%   (v 3.10a), page 603                                         %
%---------------------------------------------------------------%
\documentclass[border=5mm]{standalone}
\usepackage{tikz}
\usetikzlibrary{chains}

\begin{document}
    \begin{tikzpicture}[
start chain = circle placed {at=(150+\tikzchaincount*30:\R)},% 150 is the start angle
   C/.style = {circle, draw, fill=white, 
               inner sep=0pt, minimum size= 2.2em} % "minimum size" = "circle diameter"
                        ]
\def\R{3}   % Table radius
% Title
\node[font=\large] at (0,\R+1) {[Seats of a round table]};
% Table + dot in center
\draw[thick,fill=brown!30] (0,0) circle[radius=\R];
\draw[fill] (0,0) circle[radius=1mm];
% Seats (changes the number 150 (determines the starting angle) 
%        in the "start chain" option to rotate the seat sequence)
\foreach \i in {12,...,1}% seats number sequence going in clockwise direction
\node [C, on chain] {\i};
    \end{tikzpicture}
\end{document}

Above MWE I stored in my barn of attractive solution of use of chains library for future use.

enter image description here

Homework:

Based on above MWE write own MWE which will reproduce the following image:

enter image description here

Happy TeX-ing :-)

3

screenshot

This kind of chart is very easy to build with the chain library. Here is the example of the Nodes on a chain section of the manual, slightly modified to obtain a result similar to yours. If you want other modifications, ask for it !

\documentclass[border=5mm]{standalone}
\usepackage{tikz}
\usetikzlibrary {chains}

\begin{document}



\begin{tikzpicture}[start chain=circle placed {at=(\tikzchaincount*30:1.5)}]
\foreach \i in {1,...,12}
\node [on chain,draw,circle,inner sep=0pt,minimum size=15pt] {\i};
\draw (circle-1) -- (circle-10);
\end{tikzpicture}

\end{document} 
5
  • 2
    Attractive answer (+1) , I liked it!
    – Zarko
    Nov 7, 2021 at 7:53
  • @Zarko Thank you, I added this in order to publicize this very nice chains library which is not often used in the answers here, which I regret.
    – AndréC
    Nov 7, 2021 at 9:20
  • Re-welcomeeeeee :-))))
    – Sebastiano
    Nov 8, 2021 at 20:28
  • 1
    @Sebastiano Hi ! How are you doing after the flood disaster in Sicily?
    – AndréC
    Nov 8, 2021 at 20:33
  • After two days of a tropical storm on Thursday, November 4, African heat. Yesterday 27 degrees!!! Lots of humidity and as usual I correct my students' homework and study to prepare for class. I confess that I hate correcting homework especially because I have to decipher the spelling and the incomprehensible mathematical/physical passages.
    – Sebastiano
    Nov 8, 2021 at 20:43
2

If You want a more realistic seats around the table try this code (the commented line is for symmetry control):

\documentclass{article}
\usepackage{tikz,graphicx}
\usetikzlibrary{calc}
\begin{document}
    \noindent
    \begin{tikzpicture}[scale=1]
        \foreach \i in {1,...,12}{
        \draw[line width=4pt,rotate=30*\i,cyan] (5,-1) arc[radius=1, start angle=-80, end angle=80];
        \draw[red] (30*\i:5.3) node {\Large \bf $\i$};
    }
    \draw[line width=3pt,fill=brown!30] (0,0) circle (5);
    \draw[line width=3pt,fill=black] (0,0) circle (.2);
    %\draw[dotted] (0,-7)--(0,7);
    \end{tikzpicture}
\end{document}

The code produce this picture:

enter image description here

1

Another option:

  1. Layout the seats using the circular library.
  2. Form the circle using the routing library to bend the edges between the nodes.
  3. Find the centre of the circle using the graph's barycentric co-ordinates.
  4. Find the edge of the table using circle through from the through library.
  5. Put the "table" on the background layer.
  6. Add the title using the positioning library.
  7. Compile with lualatex

enter image description here

% !TEX TS-program = lualatex
\PassOptionsToPackage{svgnames}{xcolor}
\documentclass[tikz,border=3pt]{standalone}
\usetikzlibrary{graphs,graphdrawing,through,backgrounds,positioning}
\usegdlibrary{circular,routing}

\begin{document}
\begin{tikzpicture}[font=\sffamily]
% The seats
\graph [simple necklace layout, % circular layout
necklace routing, % bend edges
grow'= south, % orientation / starting point for 1
node sep=1em,
nodes={draw,fill=white,circle,align=center,text width=4mm},
]
{
1 -- 2 -- 3 -- 4 -- 5 -- 6 -- 7 -- 8 -- 9 -- 10 -- 11 -- 12 -- 1
};
% Center of table. Remove draw and fill if centre point is not required.
\node[draw=white,circle,fill=Tan,radius=2pt] (C) at (barycentric cs:1=0.5,7=0.5) {};
% The table
\begin{pgfonlayer}{background}
\node [draw=none,fill=Sienna,circle through=(7)] at (C) {};
\end{pgfonlayer}
%Title
\node[font=\bfseries\sffamily,above=2pt of 1] {[Seats of a Round Table]};
\end{tikzpicture}
\end{document}
0

I'm really glad I found this thread bc it's allowed me to mess around with the code and create some different shapes I'm looking for. However, I'm not into coding and the manual isn't clicking for me at all. Could anyone advise me on how to make a simple template for the original design where you can modify the number of seats in the table? I was able to do it with this code but to be honest I'm not sure what I did

\documentclass[border=2mm,tikz]{standalone}

\begin{document}
\begin{tikzpicture}
\def\R{5}   % Table radius
\def\r{0.5} % Seat radius

% Table
\draw[thick,fill=white] (0,0) circle (\R);
% Seats (change the number 180 to rotate the seats)
\foreach\i in {1,...,24}  
  \draw[fill=white] (180-15*\i:\R) circle (\r) node {$\i$};
% Center (comment it or remove it if you don't want the center shown)

\end{tikzpicture}
\end{document}

enter image description here

1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.