1

I want to draw events on top of each other on a time-line. As an example, I want to draw following figure, where event boxes could be place in different locations:

enter image description here


For https://tex.stackexchange.com/a/436306/127048 I was able to come up with:

\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}

output:

enter image description here

Related: https://tex.stackexchange.com/a/210370/127048

alper
  • 1,389

1 Answers1

4

Like this?

enter image description here

Code:

\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}

UPDATE FOR DASHED LINES:

\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}

Final update:

\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}

Output:

enter image description here