答案1
應OP要求更新2
我創建了一種新樣式,稱為from infty
來表示 的間隔-infinity
。為了將文字放置在圖形下方,我將邊界框命名為 ax 並在其下方放置了一個節點。
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](c) to["2"{draw,circle},my curve] (b) to ["3"{draw,circle},my curve] (a) to ["1"{draw,circle},to infty](z);
\end{scope}
\node[below] at (axe.south){My axis};%<-- node to add caption
\end{tikzpicture}
\end{document}
根據 OP 的要求進行更新
我創建了一種新樣式,稱為to infty
表示無窮大間隔。為了將文字放置在圖形下方,我命名了邊界框axe
並在其下方放置了一個節點。
程式碼被註解掉了%<--
。
\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](z);
\end{scope}
\node[below] at (axe.south){My axis};%<-- node to add caption
\end{tikzpicture}
\end{document}
曲線參數
這兩種樣式設定好了,預設就出現上圖了。可以修改高度曲線及其曲率具有以下參數。例如my curve=12mm of .4
意味著曲線有高度的12 mm
並且那個控制點貝塞爾曲線的0.4
和1-0.4=0.6
位於路徑的 和 處。
\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);
第一個答案
我重複使用了我的曲線7我在這裡寫的程式碼。我給它重命名了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}}
我定義了一個pic
允許您繪製勾號並在下面寫入文字的函數。
pics/tick/.style={code={\draw ++(0,-.2)node[below]{#1}--++(0,.4);}}
結果:
代碼:
\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](z);
\end{tikzpicture}
\end{document}