# How to improve the figure?

I want to draw smaller circles tangent to each other and tangent to the larger circle, as in the figure.

But, my figure does not appear with I would like, with the small circles really tangent to the larger circle .

\documentclass[12pt]{article}

\usepackage{tikz}

\begin{document}

\begin{center}

\begin{tikzpicture}[scale=1.2]
\draw[ultra thick, red!95] (0,0) circle [radius=2.9];
\draw[ultra thick, blue!90] (3.4,2) circle [radius=1];
\draw[ultra thick, yellow!90] (2,3.4) circle [radius=1];
\draw[ultra thick, green!90] (0,4) circle [radius=1];
\draw[ultra thick, cyan] (-2,3.4) circle [radius=1];
\draw[ultra thick, black] (-3.4,2) circle [radius=1];
\draw[ultra thick, green!90] (-4,0) circle [radius=1];
\draw[ultra thick, blue!90] (-3.4,-2) circle [radius=1];
\draw[ultra thick, cyan] (-2,-3.4) circle [radius=1];
\draw[ultra thick, blue!90] (0,-4) circle [radius=1];
\draw[ultra thick, yellow!95] (2,-3.4) circle [radius=1];
\draw[ultra thick, black] (3.4,-2) circle [radius=1];
\draw[ultra thick, green!90] (4,0) circle [radius=1];
\node at (2.2,2.2) {$\mathbf{S_{1}}$};
\node at (0.8,3)   {$\mathbf{S_{2}}$};
\node at (-0.8,3)  {$\mathbf{S_{3}}$};
\node at (-2.2,2.2){$\mathbf{S_{4}}$};
\node at (-3,0.8)  {$\mathbf{S_{5}}$};
\node at (-3,-0.8) {$\mathbf{S_{6}}$};
\node at (-2.2,-2.2){$\mathbf{S_{7}}$};
\node at (-0.8,-3){$\mathbf{S_{8}}$};
\node at (0.8,-3)   {$\mathbf{S_{9}}$};
\node at (2.2,-2.2) {$\mathbf{S_{10}}$};
\node at (3,-0.8) {$\mathbf{S_{11}}$};
\node at (3,0.8) {$\mathbf{S_{12}}$};
\end{tikzpicture}

\end{center}

\end{document}


There is a constraint here. You cannot have an arbitrary big and small radius, as well as an arbitrary number of circles, and also have them all be tangent as you describe.

The code below ensures that they are tangent, and calculates the required radius of the small circle from the given radius of the big circle.

\documentclass[12pt]{article}

\usepackage{tikz}
\usetikzlibrary{calc}

\begin{document}

\begin{center}

\begin{tikzpicture}[scale=1.2]

\def\numcircles{12}
% define the colors beforehand so they're in an array and easy to use
\def\circlecolors{blue!90, yellow!90, green!90, cyan, black, green!90, blue!90, cyan, blue!90, yellow!95, black, green!90}

% I'm doing trigonometry here....
\pgfmathsetmacro\s{sin(360/(2*\numcircles))}

% Do the circles & labels in a loop, instead of one-by-one.
\foreach\circcolor [count=\i,
evaluate={\i as \angle using {(3-\i)*360/\numcircles}}] in \circlecolors {
% this "evaluate" statement gives us the angle. The "(3-\i)"
% is to shift the starting position of the labels to match the ones in
% your picture. The negative is to ensure it goes counter-clockwise.

% first draw the circle ....

% and then add the label at an offset equal to half the angle
\node  at ({\angle+180/\numcircles}:{\bigradius+0.2}){$S_{\i}$};
}
\end{tikzpicture}

\end{center}
\end{document}


This results in the following figure:

The lines overlap, but this can be eliminated by reducing the quantity \smallradius by the line width.

Regarding the trigonometry, simply draw two small circles tangent to the big circle, and one another; connect their centers with line segments. Let "r" be the bigger radius, "a" be the angle between the centers of the smaller circles, and and "x" be the smaller radius. It should be immediate that sin(a / 2) = x / (x+r), and I've just solved for x.

Something like this? Maybe you need some calculation to exclude line width from radius. Then it becomes a math problem that is not difficult to solve.

Following pic allows you to draw a big circle and arbitrary small cirles that have the same radius and line width and surround the big circle one by one.

options

• r: radius of big circle
• num: number of the small circles
• small width: line width of small circle
• big width: line width of big circle
• pos: distance from the border of the big circle to node
• color 0: color of big circle
• color i (i >= 1): color of i th small circle

First small circle lies on 0 deg. If you have n small circles, then the second lies on 360/n deg and so on.

First node lies between the first and the second small circles, named picname-1 and so on.

\documentclass[tikz, border=1cm]{standalone}
\usetikzlibrary{fpu}
\usepackage{xparse}
\ExplSyntaxOn
\NewDocumentCommand {\myfor} { m +m } {
\int_step_variable:nNn {#1} \l_for_tl {\def\forvar{\tl_use:N \l_for_tl}#2}
}
\ExplSyntaxOff

% predefine
\myfor{50}{
\pgfkeys{/multicircles/color \forvar/.initial=black}
}
\makeatletter
\newlength\mc@r
\newlength\mc@R
\newlength\mc@rR
\newlength\mc@node

\tikzset{
mc/.pic={
\pgfkeys{/pgf/fpu, /pgf/fpu/output format=fixed}
\pgfmathsetmacro{\mc@ang}{360/\mc@num}
\pgfmathsetmacro{\mc@cos}{90-\mc@ang/2}
\pgfmathsetlength{\mc@node}{\mc@pos*\mc@rR*cos(\mc@ang/2)+(1-\mc@pos)*\mc@R}
\pgfkeys{/pgf/fpu=false}
\draw [\mc@color@main, line width=\mc@big@width] (0, 0) circle (\mc@R);
\foreach \i in {1,...,\mc@num} {
\def\temp@color{\pgfkeysvalueof{/multicircles/color \i}}
\draw [\temp@color, line width=\mc@small@width] ({(\i-1)*\mc@ang}:\mc@rR) circle (\mc@r);
\coordinate (-\i) at ({(\i-0.5)*\mc@ang}:\mc@node);
}
},
/multicircles/.search also=/tikz,
/multicircles/.cd,
color 0/.store in=\mc@color@main,
color 0=black,
num/.store in=\mc@num, num=6,
big width/.store in=\mc@big@width,
big width=1.6pt,
small width/.store in=\mc@small@width,
small width=1.6pt,
pos/.store in=\mc@pos, pos=.3,
}
\makeatother
\newcommand{\multicircles}[1][]{
\pic [pic type=mc, /multicircles/.cd,#1];
}
\newcommand{\multicirclesset}[1]{\pgfqkeys{/multicircles}{#1}}
\multicirclesset{
colors/.code args={#1!#2!#3}{
\myfor{#2}{
\pgfmathparse{\forvar/#2*100}
\edef\temp{
\noexpand\multicirclesset{color \forvar=#1!\pgfmathresult!#3}
}
\temp
}
}
}

\begin{document}
\begin{tikzpicture}
\multicircles[
r=2cm, num=6, color 0=red!60,
big width=3pt, small width=3pt,
colors=red!6!blue,
at={(0, 0)},
name=a,
]
\foreach \i in {1,...,6} {
\node [font=\small] at (a-\i) {$S_{\i}$};
}
\multicircles[
r=3cm, num=12, color 0=red!60,
big width=2pt, small width=4pt,
colors=yellow!12!cyan,
at={(12, 0)},
name=b,
]
\foreach \i in {1,...,12} {
\node [font=\tiny] at (b-\i) {$S_{\i}$};
}
\multicircles[
r=4cm, num=19, color 0=red!60,
big width=8pt, small width=5pt,
colors=green!19!teal,
at={(24, 0)},
name=c,
pos=-.5,
]
\foreach \i in {1,...,19} {
\node at (c-\i) {$S_{\i}$};
}
\end{tikzpicture}
\end{document}