Tikzpicture 时间轴 + underbrace

Tikzpicture 时间轴 + underbrace

我用 ticzpicture 创建了一个时间线,看​​起来不错(并且可以使用),但我想知道是否有办法在它下面放置带有文本的下括号?下面是一张我所指的图片: 在此处输入图片描述

这是我的代码:

    \documentclass[12pt,a4paper]{article}

\usepackage{tikz}

\usetikzlibrary{timeline}

\begin{document}

\begin{tikzpicture}[timespan={}]

    \timeline[custom interval=true]{\bfseries 2014, \bfseries 2015, \bfseries 2016, \bfseries 2017, \bfseries 2018}

    \begin{phases}

            %A 2014
            \phase{between week=1 and 2 in -0.5,involvement degree=2.25cm}
            %C 2014
            \phase{between week=1 and 2 in -0.1,involvement degree=2.25cm}
            %R 2014
            \phase{between week=1 and 2 in 0.3,involvement degree=2.25cm}


            %A 2016
            \phase{between week=2 and 3 in 0,involvement degree=2.25cm,phase color=blue!80!cyan}
            %C 2016
            \phase{between week=2 and 3 in 0.4,involvement degree=2.25cm,phase color=blue!80!cyan}
            %R 2016
            \phase{between week=3 and 4 in 0.05,involvement degree=2.25cm,phase color=blue!80!cyan}



            %A 2018
            \phase{between week=3 and 4 in 0.5,involvement degree=2.25cm,phase color=green!50!black}
            %C 2018
            \phase{between week=4 and 5 in -0.1,involvement degree=2.25cm,phase color=green!50!black}
            %R 2018
            \phase{between week=4 and 5 in 1.4,involvement degree=2.25cm,phase color=green!50!black}


    \end{phases}
    %2014
            \addmilestone{at=phase-1.90,direction=90:3.5cm,text={Announcement},text options={above}}
            \addmilestone{at=phase-1.270,direction=270:1.5cm,text={Date},text options={below}}


            \addmilestone{at=phase-2.90,direction=90:2.5cm,text={Clarification},text options={above}}
            \addmilestone{at=phase-2.270,direction=270:2.5cm,text={Date},text options={below}}


            \addmilestone{at=phase-3.90,direction=90:1.5cm,text={Results},text options={above}}
            \addmilestone{at=phase-3.270,direction=270:3.5cm,text={Date},text options={below}}



        %2016

            \addmilestone{at=phase-4.90,direction=90:3.5cm,text={Announcement},text options={above}}
            \addmilestone{at=phase-4.270,direction=270:1.5cm,text={Date},text options={below}}


            \addmilestone{at=phase-5.90,direction=90:2.5cm,text={Clarification},text options={above}}
            \addmilestone{at=phase-5.270,direction=270:2.5cm,text={Date},text options={below}}


            \addmilestone{at=phase-6.90,direction=90:1.5cm,text={Results},text options={above}}
            \addmilestone{at=phase-6.270,direction=270:3.5cm,text={Date},text options={below}}


        %2018

            \addmilestone{at=phase-7.90,direction=90:3.5cm,text={Announcement},text options={above}}
            \addmilestone{at=phase-7.270,direction=270:1.5cm,text={Date},text options={below}}


            \addmilestone{at=phase-8.90,direction=90:2.5cm,text={Clarification},text options={above}}
            \addmilestone{at=phase-8.270,direction=270:2.5cm,text={Date},text options={below}}


            \addmilestone{at=phase-9.90,direction=90:1.5cm,text={Results},text options={above}}
            \addmilestone{at=phase-9.270,direction=270:3.5cm,text={Date},text options={below}}

    \end{tikzpicture}

\end{document}

任何帮助都将不胜感激!:) 谢谢!

答案1

也许是这样的?

\documentclass[border = 10pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{timeline}
\usetikzlibrary{decorations.pathreplacing}

\begin{document}
\begin{tikzpicture}[timespan={}]

\timeline[custom interval=true]{\bfseries 2014, \bfseries 2015, \bfseries 2016, \bfseries 2017, \bfseries 2018}

\begin{phases}

    %A 2014
    \phase{between week=1 and 2 in -0.5,involvement degree=2.25cm}
    %C 2014
    \phase{between week=1 and 2 in -0.1,involvement degree=2.25cm}
    %R 2014
    \phase{between week=1 and 2 in 0.3,involvement degree=2.25cm}


    %A 2016
    \phase{between week=2 and 3 in 0,involvement degree=2.25cm,phase color=blue!80!cyan}
    %C 2016
    \phase{between week=2 and 3 in 0.4,involvement degree=2.25cm,phase color=blue!80!cyan}
    %R 2016
    \phase{between week=3 and 4 in 0.05,involvement degree=2.25cm,phase color=blue!80!cyan}



    %A 2018
    \phase{between week=3 and 4 in 0.5,involvement degree=2.25cm,phase color=green!50!black}
    %C 2018
    \phase{between week=4 and 5 in -0.1,involvement degree=2.25cm,phase color=green!50!black}
    %R 2018
    \phase{between week=4 and 5 in 1.4,involvement degree=2.25cm,phase color=green!50!black}


\end{phases}
%2014
    \addmilestone{at=phase-1.90,direction=90:3.5cm,text={Announcement},text options={above}}
    \addmilestone{at=phase-1.270,direction=270:1.5cm,text={Date},text options={below}}


    \addmilestone{at=phase-2.90,direction=90:2.5cm,text={Clarification},text options={above}}
    \addmilestone{at=phase-2.270,direction=270:2.5cm,text={Date},text options={below}}


    \addmilestone{at=phase-3.90,direction=90:1.5cm,text={Results},text options={above}}
    \addmilestone{at=phase-3.270,direction=270:3.5cm,text={Date},text options={below}}



%2016

    \addmilestone{at=phase-4.90,direction=90:3.5cm,text={Announcement},text options={above}}
    \addmilestone{at=phase-4.270,direction=270:1.5cm,text={Date},text options={below}}


    \addmilestone{at=phase-5.90,direction=90:2.5cm,text={Clarification},text options={above}}
    \addmilestone{at=phase-5.270,direction=270:2.5cm,text={Date},text options={below}}


    \addmilestone{at=phase-6.90,direction=90:1.5cm,text={Results},text options={above}}
    \addmilestone{at=phase-6.270,direction=270:3.5cm,text={Date},text options={below}}


%2018

    \addmilestone{at=phase-7.90,direction=90:3.5cm,text={Announcement},text options={above}}
    \addmilestone{at=phase-7.270,direction=270:1.5cm,text={Date},text options={below}}


    \addmilestone{at=phase-8.90,direction=90:2.5cm,text={Clarification},text options={above}}
    \addmilestone{at=phase-8.270,direction=270:2.5cm,text={Date},text options={below}}


    \addmilestone{at=phase-9.90,direction=90:1.5cm,text={Results},text options={above}}
    \addmilestone{at=phase-9.270,direction=270:3.5cm,text={Date},text options={below}}

    \draw [decorate, blue, decoration = {brace, amplitude = 10pt, mirror, raise = 4pt}]
    ([yshift = -5cm]phase-1.180) -- ([yshift = -5cm]phase-3.0)
    node [black, midway, yshift = -0.5cm, align = center] {Some text \\ with breaks};

    \draw [decorate, red, decoration = {brace, amplitude = 10pt, mirror, raise = 4pt}]
    ([yshift = -5cm]phase-4.180) -- ([yshift = -5cm]phase-6.0)
    node [black, midway, yshift = -0.5cm, align = center] {extra text};

    \draw [decorate, green!80!black, decoration = {brace, amplitude = 10pt, mirror, raise = 4pt}]
    ([yshift = -5cm]phase-7.180) -- ([yshift = -5cm]phase-9.0)
    node [black, midway, yshift = -0.5cm, align = center] {This phase is the best};


\end{tikzpicture}
\end{document}

在此处输入图片描述

答案2

欢迎来到 TeX.SE!这个网站的目的是交换代码。不幸的是,你的帖子中缺少序言,这意味着那些愿意回答的人必须进行推测。所以我猜测你已经下载了timeline已从以下位置下载了库这里。查看代码,我还没有看到任何明显的方法来优雅地添加括号而不更改库代码。然而,人们总是可以通过使用every node/.append style诸如此类的东西偷偷地将某些东西塞进代码中来“破解”它。当然,这比以不同方式编写库可能出现的解决方案更脆弱。

\documentclass[tikz,border=3.14mm]{standalone}
\usetikzlibrary{timeline,fit,decorations.pathreplacing}
\newcounter{mynode}
\tikzset{step node/.code={\stepcounter{mynode}%\typeout{\themynode}
}}
\begin{document}
\begin{tikzpicture}[timespan={},every node/.append style={step node,
alias=mynode-\themynode}]

\timeline[custom interval=true]{\bfseries 2014, \bfseries 2015, \bfseries 2016, \bfseries 2017, \bfseries 2018}

\begin{phases}

        %A 2014
        \phase{between week=1 and 2 in -0.5,involvement degree=2.25cm}
        %C 2014
        \phase{between week=1 and 2 in -0.1,involvement degree=2.25cm}
        %R 2014
        \phase{between week=1 and 2 in 0.3,involvement degree=2.25cm}


        %A 2016
        \phase{between week=2 and 3 in 0,involvement degree=2.25cm,phase color=blue!80!cyan}
        %C 2016
        \phase{between week=2 and 3 in 0.4,involvement degree=2.25cm,phase color=blue!80!cyan}
        %R 2016
        \phase{between week=3 and 4 in 0.05,involvement degree=2.25cm,phase color=blue!80!cyan}



        %A 2018
        \phase{between week=3 and 4 in 0.5,involvement degree=2.25cm,phase color=green!50!black}
        %C 2018
        \phase{between week=4 and 5 in -0.1,involvement degree=2.25cm,phase color=green!50!black}
        %R 2018
        \phase{between week=4 and 5 in 1.4,involvement degree=2.25cm,phase color=green!50!black}


\end{phases}
%2014
        \addmilestone{at=phase-1.90,direction=90:3.5cm,text={Announcement},text options={above}}
        \addmilestone{at=phase-1.270,direction=270:1.5cm,text={Date},text options={below}}


        \addmilestone{at=phase-2.90,direction=90:2.5cm,text={Clarification},text options={above}}
        \addmilestone{at=phase-2.270,direction=270:2.5cm,text={Date},text options={below}}


        \addmilestone{at=phase-3.90,direction=90:1.5cm,text={Results},text options={above}}
        \addmilestone{at=phase-3.270,direction=270:3.5cm,text={Date},text options={below}}



    %2016

        \addmilestone{at=phase-4.90,direction=90:3.5cm,text={Announcement},text options={above}}
        \addmilestone{at=phase-4.270,direction=270:1.5cm,text={Date},text options={below}}


        \addmilestone{at=phase-5.90,direction=90:2.5cm,text={Clarification},text options={above}}
        \addmilestone{at=phase-5.270,direction=270:2.5cm,text={Date},text options={below}}


        \addmilestone{at=phase-6.90,direction=90:1.5cm,text={Results},text options={above}}
        \addmilestone{at=phase-6.270,direction=270:3.5cm,text={Date},text options={below}}


    %2018

        \addmilestone{at=phase-7.90,direction=90:3.5cm,text={Announcement},text options={above}}
        \addmilestone{at=phase-7.270,direction=270:1.5cm,text={Date},text options={below}}


        \addmilestone{at=phase-8.90,direction=90:2.5cm,text={Clarification},text options={above}}
        \addmilestone{at=phase-8.270,direction=270:2.5cm,text={Date},text options={below}}


        \addmilestone{at=phase-9.90,direction=90:1.5cm,text={Results},text options={above}}
        \addmilestone{at=phase-9.270,direction=270:3.5cm,text={Date},text options={below}}
\node[fit=(mynode-17) (mynode-19) (mynode-21)] (f1){};
\draw[decorate,decoration=brace,thick] (f1.south east) -- (f1.south west)
node[midway,below]{something};
\node[fit=(mynode-23) (mynode-25) (mynode-27)] (f2){};
\draw[decorate,decoration=brace,thick] (f2.south east) -- (f2.south west)
node[midway,below]{something else};
\node[fit=(mynode-29) (mynode-31) (mynode-33)] (f3){};
\draw[decorate,decoration=brace,thick] (f3.south east) -- (f3.south west)
node[midway,below]{hibernate};
\end{tikzpicture}
\end{document}

在此处输入图片描述

另一种选择是,以不太脆弱的方式产生相同的结果,但需要更多的输入,即

\documentclass[tikz,border=3.14mm]{standalone}
\usetikzlibrary{timeline,fit,decorations.pathreplacing}
\begin{document}
\begin{tikzpicture}[timespan={}]

\timeline[custom interval=true]{\bfseries 2014, \bfseries 2015, \bfseries 2016, \bfseries 2017, \bfseries 2018}

\begin{phases}

        %A 2014
        \phase{between week=1 and 2 in -0.5,involvement degree=2.25cm}
        %C 2014
        \phase{between week=1 and 2 in -0.1,involvement degree=2.25cm}
        %R 2014
        \phase{between week=1 and 2 in 0.3,involvement degree=2.25cm}


        %A 2016
        \phase{between week=2 and 3 in 0,involvement degree=2.25cm,phase color=blue!80!cyan}
        %C 2016
        \phase{between week=2 and 3 in 0.4,involvement degree=2.25cm,phase color=blue!80!cyan}
        %R 2016
        \phase{between week=3 and 4 in 0.05,involvement degree=2.25cm,phase color=blue!80!cyan}



        %A 2018
        \phase{between week=3 and 4 in 0.5,involvement degree=2.25cm,phase color=green!50!black}
        %C 2018
        \phase{between week=4 and 5 in -0.1,involvement degree=2.25cm,phase color=green!50!black}
        %R 2018
        \phase{between week=4 and 5 in 1.4,involvement degree=2.25cm,phase color=green!50!black}


\end{phases}
%2014
        \addmilestone{at=phase-1.90,direction=90:3.5cm,text={Announcement},text options={above}}
        \begin{scope}[every node/.append style={alias=mynode-1}]
        \addmilestone{at=phase-1.270,direction=270:1.5cm,text={Date},text
        options={below}}
        \end{scope}


        \addmilestone{at=phase-2.90,direction=90:2.5cm,text={Clarification},text options={above}}
        \begin{scope}[every node/.append style={alias=mynode-2}]
        \addmilestone{at=phase-2.270,direction=270:2.5cm,text={Date},text options={below}}
        \end{scope}

        \addmilestone{at=phase-3.90,direction=90:1.5cm,text={Results},text options={above}}
        \begin{scope}[every node/.append style={alias=mynode-3}]
        \addmilestone{at=phase-3.270,direction=270:3.5cm,text={Date},text options={below}}
        \end{scope}


    %2016

        \addmilestone{at=phase-4.90,direction=90:3.5cm,text={Announcement},text options={above}}
        \begin{scope}[every node/.append style={alias=mynode-4}]
        \addmilestone{at=phase-4.270,direction=270:1.5cm,text={Date},text options={below}}
        \end{scope}

        \addmilestone{at=phase-5.90,direction=90:2.5cm,text={Clarification},text options={above}}
        \begin{scope}[every node/.append style={alias=mynode-5}]
        \addmilestone{at=phase-5.270,direction=270:2.5cm,text={Date},text options={below}}
        \end{scope}

        \addmilestone{at=phase-6.90,direction=90:1.5cm,text={Results},text options={above}}
        \begin{scope}[every node/.append style={alias=mynode-6}]
        \addmilestone{at=phase-6.270,direction=270:3.5cm,text={Date},text options={below}}
        \end{scope}

    %2018

        \addmilestone{at=phase-7.90,direction=90:3.5cm,text={Announcement},text options={above}}
        \begin{scope}[every node/.append style={alias=mynode-7}]
        \addmilestone{at=phase-7.270,direction=270:1.5cm,text={Date},text options={below}}
        \end{scope}

        \addmilestone{at=phase-8.90,direction=90:2.5cm,text={Clarification},text options={above}}
        \begin{scope}[every node/.append style={alias=mynode-8}]
        \addmilestone{at=phase-8.270,direction=270:2.5cm,text={Date},text options={below}}
        \end{scope}

        \addmilestone{at=phase-9.90,direction=90:1.5cm,text={Results},text options={above}}
        \begin{scope}[every node/.append style={alias=mynode-9}]
        \addmilestone{at=phase-9.270,direction=270:3.5cm,text={Date},text options={below}}
        \end{scope}

        \node[fit=(mynode-1) (mynode-2) (mynode-3)] (f1){};
        \draw[decorate,decoration=brace,thick] (f1.south east) -- (f1.south west)
        node[midway,below]{something};
        \node[fit=(mynode-4) (mynode-5) (mynode-6)] (f2){};
        \draw[decorate,decoration=brace,thick] (f2.south east) -- (f2.south west)
        node[midway,below]{something else};
        \node[fit=(mynode-7) (mynode-8) (mynode-9)] (f3){};
        \draw[decorate,decoration=brace,thick] (f3.south east) -- (f3.south west)
        node[midway,below]{hibernate};
\end{tikzpicture}
\end{document}

相关内容