在 TikZ 中绘制带有文本描述的数字线

在 TikZ 中绘制带有文本描述的数字线

我想知道如何使用 TikZ 构建以下数字线:

https://i.stack.imgur.com/oQtaD.jpg

我尝试过阅读这里的其他问题,但我遇到的主要挑战是:(1)在数字线中间创建三个点“...”;(2)将花括号分成两部分;(3)将文本放在一些曲线的上方和下方。

谢谢你!

答案1

  • 在您的问题中,您没有显示所需图像的草图,只有无法访问的链接。
  • 我希望@Tom 回答中的图像足够接近您所追求的。
  • 我会以稍微不同的方式绘制这幅图,因为我喜欢:

在此处输入图片描述

  • 我尝试编写尽可能简洁、结构清晰的 MWE:
\documentclass[border=3.141592]{standalone}
\usepackage{amsmath}
\usepackage{tikz}
\usetikzlibrary{arrows.meta, 
                decorations.pathreplacing,%
                    calligraphy,% had to be after decorations.pathreplacing
                calc}

\begin{document}
    \begin{tikzpicture}[
             > = Straight Barb,
BC/.style args = {#1/#2}{
        decorate,
        decoration={calligraphic brace, amplitude=6pt,
                    pre =moveto, pre  length=1pt,
                    post=moveto, post length=1pt,
                    raise=#1,
                    #2,% for mirroring of brace
                    },
            ultra thick},
                        ]
\draw [ultra thick,->] (-7.5,0) -- (7.5,0);
    \foreach \i [count=\x from -6] in  {-23,-22,-21,-20,-19,\dotsm,1,2,...,6}
\draw[thick] (\x,3mm) -- ++ (0,-6mm) node (n\x) [below] {$\i$};
%
\draw[BC=4mm/]          (-6,0) -- node[above=6mm] {other text} (-2,0); 
\draw[BC=8mm/mirror]    ( 0,0) -- coordinate[below=11mm] (aux)  (5,0);
\draw[<->, semithick, densely dashed, rounded corners] 
    (n-6) -- node[fill=white] {some text} ++ (0,-1.3) -| (aux);
    \end{tikzpicture}
\end{document}

答案2

这是一个解决方案。有没有办法让代码更简洁?有什么建议吗?

\documentclass[border=1cm]{standalone}
\usepackage{tikz}
\usetikzlibrary{arrows.meta, decorations.pathreplacing,calc}

\begin{document}
\begin{tikzpicture}
\draw [line width=5pt,-{Triangle[length=0.5cm,width=0.5cm]}] (-7.5,0) -- (7.5,0);
\foreach \x in {-6,...,-2} {
\draw [line width=2pt] (\x,-0.5) node (bx\x) [font=\Large,xshift=-6pt,below=0.5cm] {\pgfmathparse{\x-17}$\mathbf{\pgfmathprintnumber{\pgfmathresult}}$} -- (\x,0.5) coordinate (tx\x);}
\draw [line width=2pt] (-1,-0.5) node (bx-1)  [font=\bfseries\Large,below=0.75cm] {\dots} -- (-1,0.5) coordinate (tx-1);
\foreach \x in {0,...,6} {
\draw [line width=2pt] (\x,-0.5) node (bx\x) [font=\Large,below=0.5cm] {\pgfmathparse{\x+1}$\mathbf{\pgfmathprintnumber{\pgfmathresult}}$} -- (\x,0.5) coordinate (tx\x);}
\draw [decorate,decoration={brace,raise=10pt,amplitude=20pt}] (tx-6) -- (tx-1) node (TB) [midway,above=1.2cm,font=\large] {\textbf{Other Text}};
\draw [decorate,decoration={brace,raise=10pt,amplitude=20pt,mirror}] (bx0.south) -- (bx6.south) node (BB) [midway,below=1cm] {};
\draw [{[scale=2]Triangle}-] ($(bx-6)+(6pt,-10pt)$) -- ++(0,-0.7) node (ST) [below=4pt,font=\large] {\textbf{Some Text}};
\draw [shorten <=6pt,shorten >=6pt,-{[scale=2]Triangle}] (ST.south) .. controls +(-80:1.5cm) and +(200:1.5cm) .. (BB.south west);
\end{tikzpicture}
\end{document}

在此处输入图片描述

相关内容