I want to draw a figure (in overleaf) as shown below: a number axis with some intervals indicated by circled number:

1 Answers
Update 2 on request of OP
I created a new style called from infty to represent the interval from -infinity. To place text under the figures, I named the bounding box axe and placed a node underneath it.
from infty/.style args={#1of#2}{%<-- new style "from infty"
to path={($(\tikztostart)!#1!90:(\tikztotarget)$).. controls ($(\tikztostart)!1-#2!(\tikztotarget)!#1!90:(\tikztotarget)$)
.. (\tikztotarget) \tikztonodes}}
\documentclass[tikz,border=5mm]{standalone}
%\usepackage{tikz}
\usetikzlibrary{arrows.meta,calc,quotes}
\begin{document}
\tikzset{my curve/.style args={#1of#2}{
to path={.. controls ($(\tikztostart)!#2!(\tikztotarget)!#1!90:(\tikztotarget)$)
and ($(\tikztostart)!1-#2!(\tikztotarget)!#1!90:(\tikztotarget)$)
.. (\tikztotarget)\tikztonodes}},
my curve/.default={7mm of 0.25},
to infty/.style args={#1of#2}{%<-- new style "to infty"
to path={.. controls ($(\tikztostart)!#2!(\tikztotarget)!#1!90:(\tikztotarget)$)
.. ($(\tikztotarget)!#1!90:(\tikztotarget)$) \tikztonodes}},
from infty/.style args={#1of#2}{%<-- new style "from infty"
to path={($(\tikztostart)!#1!90:(\tikztotarget)$).. controls ($(\tikztostart)!1-#2!(\tikztotarget)!#1!90:(\tikztotarget)$)
.. (\tikztotarget) \tikztonodes}},
to infty/.default={7mm of 0.4},
from infty/.default={7mm of 0.4}}
\begin{tikzpicture} [pics/tick/.style={code={\draw ++(0,-.2)node[below]{#1}--++(0,.4);}}]
\begin{scope}[local bounding box=axe]%<-- bounding box "axe"
\coordinate (z') at (-2,0);
\coordinate (c) at (1,0);
\coordinate (b) at (4,0);
\coordinate (a) at (6,0);
\coordinate (z) at (9,0);
\draw[-{Stealth[]}] (-2,0)--(10,0);
\pic at (c){tick=c};
\pic at (b){tick=b};
\pic at (a) {tick=a};
%\pic at (z) {tick};
\draw (z')to"4"{draw,circle},from infty to["2"{draw,circle},my curve] (b) to ["3"{draw,circle},my curve] (a) to "1"{draw,circle},to infty;
\end{scope}
\node[below] at (axe.south){My axis};%<-- node to add caption
\end{tikzpicture}
\end{document}
Update on request of the OP
I created a new style called to infty to represent the interval to infinity.
To place text under the figures, I named the bounding box axe and placed a node underneath it.
The code is commented out with %<-- .
\documentclass[tikz,border=5mm]{standalone}
%\usepackage{tikz}
\usetikzlibrary{arrows.meta,calc,quotes}
\begin{document}
\tikzset{my curve/.style args={#1of#2}{
to path={.. controls ($(\tikztostart)!#2!(\tikztotarget)!#1!90:(\tikztotarget)$)
and ($(\tikztostart)!1-#2!(\tikztotarget)!#1!90:(\tikztotarget)$)
.. (\tikztotarget)\tikztonodes}},
my curve/.default={7mm of 0.25},
to infty/.style args={#1of#2}{%<-- new style "to infty"
to path={.. controls ($(\tikztostart)!#2!(\tikztotarget)!#1!90:(\tikztotarget)$)
.. ($(\tikztotarget)!#1!90:(\tikztotarget)$) \tikztonodes}},
to infty/.default={7mm of 0.4}}
\begin{tikzpicture} [pics/tick/.style={code={\draw ++(0,-.2)node[below]{#1}--++(0,.4);}}]
\begin{scope}[local bounding box=axe]%<-- bounding box "axe"
\coordinate (c) at (1,0);
\coordinate (b) at (4,0);
\coordinate (a) at (6,0);
\coordinate (z) at (9,0);
\draw[-{Stealth[]}] (0,0)--(10,0);
\pic at (c){tick=c};
\pic at (b){tick=b};
\pic at (a) {tick=a};
%\pic at (z) {tick};
\draw (c) to["2"{draw,circle},my curve] (b) to ["3"{draw,circle},my curve] (a) to "1"{draw,circle},to infty;
\end{scope}
\node[below] at (axe.south){My axis};%<-- node to add caption
\end{tikzpicture}
\end{document}
Curve parameters
These two styles are set, by default, it appears the previous figure. It is possible to modify the height of the curve and its curvature with the following parameters.
For example my curve=12mm of .4 means that the curve has a height of 12 mm and that the control points of the bezier curve are located at 0.4 and 1-0.4=0.6 of the path.
\draw (c) to["2"{draw,circle},my curve=12mm of .4] (b) to ["3"{draw,circle},my curve=8mm of .2] (a) to ["1"{draw,circle},to infty=15mm of .6](z);
First answer
I reused the my curve 7 code I wrote here. I renamed it my curve.
\tikzset{my curve/.style args={#1of#2}{
to path={.. controls ($(\tikztostart)!#2!(\tikztotarget)!#1!90:(\tikztotarget)$)
and ($(\tikztostart)!1-#2!(\tikztotarget)!#1!90:(\tikztotarget)$)
.. (\tikztotarget)\tikztonodes}},
my curve/.default={7mm of 0.25}}
I defined a pic that allows you to draw a tick and write text underneath.
pics/tick/.style={code={\draw ++(0,-.2)node[below]{#1}--++(0,.4);}}
Result:
Code:
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{arrows.meta,calc,quotes}
\begin{document}
\tikzset{my curve/.style args={#1of#2}{
to path={.. controls ($(\tikztostart)!#2!(\tikztotarget)!#1!90:(\tikztotarget)$)
and ($(\tikztostart)!1-#2!(\tikztotarget)!#1!90:(\tikztotarget)$)
.. (\tikztotarget)\tikztonodes}},
my curve/.default={7mm of 0.25}}
\begin{tikzpicture} [pics/tick/.style={code={\draw ++(0,-.2)node[below]{#1}--++(0,.4);}}]
\coordinate (c) at (1,0);
\coordinate (b) at (4,0);
\coordinate (a) at (6,0);
\coordinate (z) at (9,0);
\draw[-{Stealth[]}] (0,0)--(10,0);
\pic at (c){tick=c};
\pic at (b){tick=b};
\pic at (a) {tick=a};
\pic at (z) {tick};
\draw (c) to["2"{draw,circle},my curve] (b) to ["3"{draw,circle},my curve] (a) to "1"{draw,circle},my curve;
\end{tikzpicture}
\end{document}
- 24,137
-
Thank you for your answer! I want region 1 represent (a, \infty), so the curve starting from $a$ should not point to any other number, how should I modify the code? One more thing, what if I want to add a caption underneath the figure? – luw Aug 28 '20 at 16:58
-
@luw Is this right for you now? – AndréC Aug 28 '20 at 18:42
-
1It's great! Thank you for your detailed explanation! – luw Aug 28 '20 at 19:20
-
Hi! Can I add a question? What if I want to represent the region (-\infty, c). I think I need to modify your "infty", but I don't know how. – luw Dec 27 '20 at 01:43
-
1@luw I just added a style for this – AndréC Dec 27 '20 at 21:07
-
You are finally back...welcome with all my heart and happy holidays. – Sebastiano Dec 27 '20 at 21:11
-
2@Sebastiano Not really, I don't have time to get involved in the site right now, I'm just answering a request. Happy New Year 2021 to you! – AndréC Dec 27 '20 at 21:41
-
@AndréC I will return my besttttt wishes for the new year and I hope for you and your family a good year that it will be better than this baddddd year. All the best...always. – Sebastiano Dec 27 '20 at 21:45
-
@AndréC Thank you so much! Happy holidays! – luw Dec 28 '20 at 07:01



