在时间线图上的其他括号上方添加括号

在时间线图上的其他括号上方添加括号

我正在尝试添加两个橙色括号,如下图所示:
期望输出

我正在努力将它们(橙色)放置在我的图表上。以下是我的 MWE:

\documentclass{standalone}
\newcommand{\ImageWidth}{11cm}
\usepackage{tikz}
\usetikzlibrary{decorations.pathreplacing,positioning, arrows.meta}

\begin{document}         
    \begin{tikzpicture}
        % draw horizontal line   
        \draw[thick, -Triangle] (0,0) -- (15,0) node[font={\normalsize},below left=4pt and -8pt]{years};
        
        % draw vertical lines
        \foreach \x in {0,4,8,10,12,14}
        \draw (\x cm,5pt) -- (\x cm,-5pt);
        
        \foreach \x/\descr in {4/t-2\Delta t_I,8/t-\Delta t_I,12/t}
        \node[font=\normalsize, text height=1.75ex,
        text depth=.5ex] at (\x,-.5) {$\descr$};
        
        \foreach \x/\descr in {10/(t-\Delta t_I)+\Delta t_X}
        \node[blue,font=\normalsize, text height=1.75ex,
        text depth=.5ex] at (\x,.5) {$\descr$};
        
        \foreach \x/\descr in {14/t+\Delta t_X}
        \node[blue,font=\normalsize, text height=1.75ex,
        text depth=.5ex] at (\x,.5) {$\descr$};
        
        % braces
        \draw [blue,thick ,decorate,decoration={brace,amplitude=8pt}] (8,0.7)  -- +(2,0) 
        node [blue,midway,above=6pt, font=\normalsize] {$\Delta X_{current}$};
        \draw [blue,thick ,decorate,decoration={brace,amplitude=8pt}] (12,0.7)  -- +(2,0) 
        node [blue,midway,above=6pt, font=\normalsize] {$\Delta X_{future}$};
        \draw [thick,decorate,decoration={brace,amplitude=8pt}] (8,-.9) -- +(-4,0)
        node [black,midway,font=\normalsize, below=6pt] {$\rho_{current}$};
        \draw [thick,decorate,decoration={brace,amplitude=8pt}] (12,-.9) -- +(-4,0)
        node [black,midway,font=\normalsize, below=6pt] {$\rho_{previous}$};
        
    \end{tikzpicture}
    
\end{document}

答案1

看看,如果以下 MWE 产生了您想要的结果:

编辑:

  • 括号上方/下方的文本颜色与括号颜色不同
  • /在第一个循环中的第 13 个数字后添加
\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{arrows.meta,
                decorations.pathreplacing,
                    calligraphy,% had to be after decorations.pathreplacing
                positioning}

\begin{document}
    \begin{tikzpicture}[
BC/.style args = {#1/#2/#3}{
        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,
        pen colour={#3}, text=#3
        },              ]
% timeline
\draw[thick,-Triangle] (0,0) -- (15,0) node[below=12pt, left] {years};
% draw ticks
\foreach \x/\i [count=\j] in {0, 
                              3/t-2\Delta t_I, 
                              7/t-\Delta t_I, 
                              9/,
                              11/t, 
                              13/}  % <--- corrected, added is /
    \draw (\x,5pt) -- ++ (0,-10pt) node (b\j) [below] {$\i$};
% braces below
\draw [BC=1mm/mirror/black] 
    (b2.south) -- node[below=2ex] {$\rho_{\mathrm{previous}}$} (b3.south);
\draw[BC=1mm/mirror/black]
    (b3.south) -- 
            node[below=2ex] {$\rho_{\mathrm{current}}$} (b5.south);
% blue braces above
\foreach \m/\i [count=\j] in {7/ ,
                              9/(t-\Delta t_I)+\Delta t_S,
                              11/ ,
                              13/t+\Delta t_S}
    \node (a\j) [above] at (\m,5pt) {$\i$};
\draw [BC=1mm/ /blue]
    (b3 |- a2.north) --
            node (s1) [above=2ex] {$\Delta S_{\mathrm{current}}$} (a2.north);
\draw [BC=1mm/ /blue]
    (a3 |- a4.north) --
        node (s2) [above=2ex] {$\Delta S_{\mathrm{future}}$} (a4.north);
% orange braces above
\draw [BC=1mm/ /orange]
    (b2 |- s1.north) --
            node [above=2ex] {$\varphi=i$} (s1.north east);
\draw [BC=5mm/ /orange]
    (a1 |- s2.north) --
            node [above=4ex] {$\varphi=j$} (s2.north east);
    \end{tikzpicture}
\end{document}
  • 正如您所观察到的,上述 MWE 与您的 MWE 相比的主要区别在于:
    • 因为使用了括号的样式calligraphy
    • 括号的样式定义在tikzpicture括号的样式在选项
    • 括号的定位使用由时间线上的节点名称和括号样式选项定义的相对坐标raise=#1
    • 只使用了两个循环(我尝试在一个循环中合并所有内容,但没有成功)

在此处输入图片描述

相关内容