9.8 Generating a timeline

By using basic TikZ functions, it’s easy to create a line and add some ticks, date values, and annotations.

This recipe will show you another colorful and pre-designed way: using the timeline library.

Getting ready

Until the timeline library officially becomes part of TikZ or becomes available on CTAN, you can download the file tikzlibrarytimeline.code.tex from its author’s repository at https://github.com/cfiandra/timeline. You can install it in the TeX tree like any other package, but the easiest way is to simply put it into the same folder as your main TeX document.

How to do it…

The timelime library builds on TikZ, but also provides its own high-level commands. Now follow these steps:

  1. Start with a document class whose paper size is big enough:
    \documentclass[a3paper]{article}

  2. Load the geometry package with the landscape option, since your diagram will be more wide than high:
    \usepackage[landscape]{geometry}

  3. Load the TikZ package:
    \usepackage{tikz}

  4. Then load the timeline TikZ library:
    \usetikzlibrary{timeline}

  5. Start the document and begin the TikZ picture:
    \begin{document}
    \begin{tikzpicture}

  6. State the number of weeks:
      \timeline{5}

  7. Define the time phases:
      \begin{phases}
    \initialphase{involvement degree=3cm,phase color=blue}
    \phase{between week=1 and 2 in 0.4,
    involvement degree=5cm,phase color=green!50!black}
    \phase{between week=2 and 3 in 0.2,
    involvement degree=6cm,phase color=red!40!black}
    \phase{between week=3 and 4 in 0.5,
    involvement degree=3cm,phase color=red!90!black}
    \phase{between week=4 and 5 in 0.3,
    involvement degree=2.5cm,phase color=red!40!yellow}
    \end{phases}

  8. Add some text nodes as annotations on the left-hand side:
      \node [xshift=-0.6cm,yshift=1cm,anchor=east,
    font=\Large\bfseries] at (phase-0.180)
    {Auhor};
    \node [xshift=-0.6cm,yshift=-1cm,anchor=east,
    font=\Large\bfseries] at (phase-0.180)
    {Publisher};

  9. Add milestones on the upper side of the timeline:
      \addmilestone{at=phase-0.120,direction=120:1cm,
    text={Concept}, text options={above}}
    \addmilestone{at=phase-0.90,direction=90:1.2cm,
    text={Outline}}
    \addmilestone{at=phase-1.110,direction=110:1.5cm,
    text={Research}}
    \addmilestone{at=phase-2.100,direction=100:1cm,
    text={Writing}}
    \addmilestone{at=phase-2.60,direction=90:1.5cm,
    text={First draft}}
    \addmilestone{at=phase-3.90,direction=90:1.2cm,
    text={Second draft}}
    \addmilestone{at=phase-4.90,direction=90:0.8cm,
    text={Approval of print draft}}

  10. Then add milestones on the lower side of the timeline:
       \addmilestone{at=phase-0.270,direction=270:1cm,
    text={Concept Review}, text options={below}}
    \addmilestone{at=phase-2.270,direction=270:1cm,
    text={First Review}}
    \addmilestone{at=phase-3.250,direction=250:0.8cm,
    text={Second Review}}
    \addmilestone{at=phase-3.300,direction=270:1.5cm,
    text={Approval required}}
    \addmilestone{at=phase-4.260,direction=270:2.2cm,
    text={Draft for printing}}
    \addmilestone{at=phase-4.300,direction=300:1cm,
    text={Publication}}

  11. End the picture and the document:
    \end{tikzpicture}
    \end{document}

  12. Compile, and examine the output:

Timeline

How it works…

With \timeline{5}, we created a filled rectangle with 5 weeks. Choose another number for more or fewer weeks. There’s a node for each week that you can use for additional drawing; simply refer to (week-1) and so on as named nodes.

Within the phases environment, we defined the filled circles. They stand for the various time phases. Let’s look at the sample phase arguments to understand their use:

  • between week=1 and 2 in 0.4: This means starting at week 1 and ending at week 2, with an offset of 0.4 for fine-tuning.
  • involvement degree: This is the radius of the phase circle.
  • phase color: This is the fill color of the phase circle.

That’s specific syntax for basic elements as such.

Finally, we added milestones. These are text nodes connected to a phase with a line:

  • at: This means the starting position. It’s good to use relative positioning, such as phase-1.north for “above the phase-1 node.” We used the phase-n.angle TikZ syntax here.
  • direction: This is given as polar values, like this: (angle:distance).
  • text: This is the text within the node. We used the text options key to customize the placement. This option is sticky, so it will be remembered. The text had been placed above until we changed text options to below, which was then kept. The library gives a nice quick start. You can use the means of TikZ for further design.
  • Previous recipe: Putting thoughts in a mind map
  • Back to start of chapter 9