如何在时间轴上绘制多个事件?

如何在时间轴上绘制多个事件?

我想在时间线上绘制事件。例如,我想绘制下图,其中事件框可以放置在不同的位置:

在此处输入图片描述


为了https://tex.stackexchange.com/a/436306/127048我想出了:

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

\begin{document}
\begin{tikzpicture}
    % draw horizontal line
    \draw[thick, -Triangle] (0,0) -- (4,0) node[font=\scriptsize,below left=3pt and -8pt]{hours};

    % draw vertical lines
    \foreach \x in {0,1,...,3}
    \draw (\x cm,3pt) -- (\x cm,-3pt);

    \foreach \x/\descr in {0/t_{1},1/t_{2},2/t_{3},3/t_{4}}
    \node[font=\scriptsize, text height=1.75ex,
    text depth=.5ex] at (\x,-.3) {$\descr$};

    % colored bar up
    \foreach \x/\perccol in
    {0/100,1/75}
    \draw[lightgray!\perccol!lightgray, line width=4pt]
    (\x,.5) -- +(1,0);

    % colored bar down
    \foreach \x/\perccol in
    {3/100,4/75,5/0}
    (\x,-.7) -- +(1,0);
\end{tikzpicture}
\end{document}

输出:

在此处输入图片描述

有关的:https://tex.stackexchange.com/a/210370/127048

答案1

像这样?

在此处输入图片描述

代码:

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

\begin{document}
    \begin{tikzpicture}
        % draw horizontal line
        \draw[thick, -Triangle] (0,0) -- (4,0) node[font=\scriptsize,below left=3pt and -8pt]{hours};
        
        % draw vertical lines
        \foreach \x in {0,1,...,3}
        \draw (\x cm,3pt) -- (\x cm,-3pt);
        
        \foreach \x/\descr in {0/t_{1},1/t_{2},2/t_{3},3/t_{4}}
        \node[font=\scriptsize, text height=1.75ex,
        text depth=.5ex] at (\x,-.3) {$\descr$};
        
        % colored bar1 up   
        \draw[lightgray!50!lightgray, line width=7pt]
        (0,.5) -- +(2,0)  node[pos=.5,white] () {one};
        
        % colored bar2 up
        \draw[lightgray!50!red, line width=7pt]
        (0,.8) -- +(2,0)  node[pos=.5,white] () {two};
        
        % colored bar2 down
        \draw[lightgray!50!green, line width=7pt]
        (2,-.6) -- +(1.5,0)  node[pos=.5,white] () {three};
    \end{tikzpicture}
\end{document}

虚线更新

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

\begin{document}
    \begin{tikzpicture}
        % draw horizontal line
        \draw[thick, -Triangle] (0,0) -- (4,0) node[font=\scriptsize,below left=3pt and -8pt]{hours};
        
        % draw vertical lines
        \foreach \x in {0,1,...,3}
        \draw (\x cm,3pt) -- (\x cm,-3pt);
        
        \foreach \x/\descr in {0/t_{1},1/t_{2},2/t_{3},3/t_{4}}
        \node[font=\scriptsize, text height=1.75ex,
        text depth=.5ex] at (\x,-.3) {$\descr$};
        
        % colored bar1 up   
        \draw[lightgray!50!lightgray, line width=7pt]
        (0,.5) -- +(2,0)  node[pos=.5,white] () {one};
        
        % colored bar2 up
        \draw[lightgray!50!red, line width=7pt]
        (0,.8) -- +(2,0)  node[pos=.5,white] () {two};
        
        % colored bar2 down
        \draw[lightgray!50!green, line width=7pt]
        (2,-.6) -- +(1.5,0)  node[pos=.5,white] () {three};
        
        % dotted lines
        \foreach \x in {0,2}
            \draw[dashed] (\x,0)--(\x,1);
        \foreach \x in {2,3.5}
            \draw[dashed] (\x,0)--(\x,-.7);
        
    \end{tikzpicture}
\end{document}

最后更新

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

\begin{document}
    \begin{tikzpicture}
        % grid
        \draw[gray!20,step=.25] (-1,-1) grid (6,2); 
        % draw horizontal line
        \draw[thick, -Triangle] (0,0) -- (4,0) node[font=\scriptsize,below left=3pt and -8pt]{hours};
        
        % draw vertical lines
        \foreach \x in {0,1,...,3}
        \draw (\x cm,3pt) -- (\x cm,-3pt);
        
        \foreach \x/\descr in {0/t_{1},1/t_{2},2/t_{3},3/t_{4}}
        \node[font=\scriptsize, text height=1.75ex,
        text depth=.5ex] at (\x,-.3) {$\descr$};
        
        % colored bar1 up   
        \draw[lightgray!50!lightgray, line width=7pt]
        (0,.5) -- +(2,0)  node[pos=.5,white] () {one};
        
        % colored bar2 up
        \draw[lightgray!50!red, line width=7pt]
        (0,.8) -- +(2,0)  node[pos=.5,white] () {two};
        
        % colored bar2 down
        \draw[lightgray!50!green, line width=7pt]
        (2,-.6) -- +(1.5,0)  node[pos=.5,white] () {three};
        
        % dotted lines
        \foreach \x in {0,2}
            \draw[dashed] (\x,0)--(\x,1);
        \foreach \x in {2,3.5}
            \draw[dashed] (\x,0)--(\x,-.7);
        
    \end{tikzpicture}
\end{document}

输出:

在此处输入图片描述

相关内容