[Tex/LaTex] Customizable Timeline

chronologychronosysmoderntimelinetikz-pgftimeline

guys!

I need to do a timeline for my Master's Thesis, and I am facing some trouble. I have tried to use two different packages: chronosys and chronology, but none of them is sufficiently customizable for my needs. So far, I am using chronosys because it is slightly more customizable than chronology, but I am not happy still. In a nutshell, I need to represent the information contained in this Table in a nice timeline:

enter image description here

When using chronosys, the best output I can obtain is this one:

enter image description here

Using this code (MWE):

\documentclass[a4paper]{report}
\usepackage{float}
\usepackage{amssymb}
\usepackage{chronosys}
\usepackage{mathtools}
\usepackage{color}
\usepackage{helvet}
\usepackage[labelfont=bf,skip=0pt,labelsep=period]{caption}
\usepackage[tableposition=top]{caption}
\renewcommand{\thefigure}{\Roman{figure}}
\renewcommand{\thetable}{\Roman{table}}
\renewcommand{\familydefault}{\sfdefault}

\begin{document}
\startchronology[align=left, startyear=2007,stopyear=2018, height=0pt, startdate=false, stopdate=false, dateselevation=0pt, arrow=false, box=false, ]
\chronograduation[event][dateselevation=0pt]{1}
\chronoperiode[color=cyan, startdate=false, stopdate=false, bottomdepth=0pt, topheight=5pt, textdepth=20pt]{2008}{2010}{}
\chronoperiode[color=olive, startdate=false, stopdate=false, bottomdepth=5pt, topheight=10pt, textdepth=25pt]{2008}{2011}{}
\chronoperiode[color=gray, startdate=false, stopdate=false, bottomdepth=10pt, topheight=15pt, textdepth=30pt]{2009}{2011}{}
\chronoperiode[color=red, startdate=false, stopdate=false, bottomdepth=15pt, topheight=20pt, textdepth=35pt]{2010}{2015}{}
\chronoperiode[color=purple, startdate=false, stopdate=false, bottomdepth=20pt, topheight=25pt, textdepth=40pt]{2010}{2013}{}
\chronoperiode[color=magenta, startdate=false, stopdate=false, bottomdepth=25pt, topheight=30pt, textdepth=45pt]{2011}{2013}{}
\chronoperiode[color=orange, startdate=false, stopdate=false, bottomdepth=30pt, topheight=35pt, textdepth=50pt]{2011}{2014}{}
\chronoperiode[color=olive, startdate=false, stopdate=false, bottomdepth=35pt, topheight=40pt, textdepth=55pt]{2011}{2012}{}
\chronoperiode[color=brown, startdate=false, stopdate=false, bottomdepth=40pt, topheight=45pt, textdepth=60pt]{2012}{2013}{}
\chronoperiode[color=teal, startdate=false, stopdate=false, bottomdepth=45pt, topheight=50pt, textdepth=65pt]{2013}{2016}{}
\chronoperiode[color=lightgray, startdate=false, stopdate=false, bottomdepth=50pt, topheight=55pt, textdepth=70pt]{2013}{2015}{}
\chronoperiode[color=lime, startdate=false, stopdate=false, bottomdepth=55pt, topheight=60pt, textdepth=75pt]{2015}{2018}{}
\stopchronology
\end{document}

What I would like is quite similar to what I already have, but with five changes. Basically, I would like the following transformations:

(a) To have the name of each country inside the colored boxes of the timeline. Alternatively, I do not mind having all the names either at the left or the right of the timeline, as a "legend" or something similar.

(b) To specify the starting and ending points of the periods by month, not by year; so that the timeline reflects more concisely the information in the Table.

(c) To have vertical lines going upwards from each year, so the timeline is easier to read. Ideally, these lines should be gray and dotted, but this is not extremely relevant.

(d) To have an horizontal line "nicely" uniting all the years in the base (I can do this with Chronosys, but it looks really ugly).

(e) To add "Figure I. Timeline of EU Bailouts" as a title of the timeline.

The answer I expect is a way of obtaining the modifications I desire either using Chronosys (which I do not think it's possible); or any other package you consider suitable for my needs. If your solution is done using another package which is not Chronosys or Chronology (probably TikZ?); I would be extremely grateful if you could provide a comprehensive and long MWE, as well as a relatively detailed explanation of what is going on, given that I am relatively new to LaTex.

If there are any mistakes in my question (particularly, if the MWE is not really minimal), feel free to edit it and improve it. Thank you all!

Best Answer

Here's another version with Tikz. The command is as follows:

\nation{mm/yyyy}{mm/yyyy}{level}{color}{label}

The month mm and year year are typed in that format, but if you're below 10, you can enter a single digit. So for January 2010, you type 1/2010. Level is the height of the bar relative to the timeline below.

You could automatize the coloring too, and get rid of an argument to type, it'd be easy to implement.

Output

enter image description here

Code

\documentclass[12pt]{article}
\usepackage[a4paper, margin=1cm, landscape]{geometry}
\usepackage{amsmath}
\usepackage{xstring}
\usepackage{tikz}
\usetikzlibrary{fit, calc}
\pagestyle{empty} 

\newcommand\anno{2008} % starting year
\newcommand\target{2018} % ending year
\newcommand\alto{36} % height
\def\months{{"jan","feb","mar","apr","may","jun","jul","aug","sep","oct","nov","dec"}}%
\pgfmathsetmacro\myend{\target-1-\anno}
\pgfmathsetmacro\tix{1/12}
\pgfmathsetmacro\myspacing{24/(\target-1-\anno)}

\newcommand\nation[5]{%
    \StrBefore{#1}{/}[\mmstart]
    \StrBehind{#1}{/}[\yystart]
    \StrBefore{#2}{/}[\mmend]
    \StrBehind{#2}{/}[\yyend]
    \pgfmathsetmacro\ymstart{(\yystart-\anno)+(1/13*\mmstart)}
    \pgfmathsetmacro\ymend{(\yyend-\anno)+(1/13*\mmend)}
    \filldraw[fill=#4!50, draw=#4,] (\ymstart,#3-.45) rectangle (\ymend,#3+.45) node [font=\scriptsize, text centered, midway, inner sep=0pt] {#5};
    \pgfmathsetmacro\mmone{\months[\mmstart-1]}
    \pgfmathsetmacro\mmtwo{\months[\mmend-1]}
    \node[rotate=90, anchor=north, inner sep=1pt, font=\tiny\scshape] at (\ymstart,#3) {\mmone};
    \node[rotate=90, anchor=south, inner sep=1pt, font=\tiny\scshape] at (\ymend,#3) {\mmtwo};
}

\begin{document}
\begin{tikzpicture}[x=\myspacing cm,y=5mm]
\centering

%draw horizontal line + years
\draw[|->, -latex] (-.5,0) -- (\myend+.5,0);
\path (0,0) -- (0,\alto);
\foreach \x [evaluate=\x as \year using int(\anno+\x)] in {0,...,\myend}{ 
    \draw (\x,0) node[below=7pt,font=\footnotesize] {$\year$}; 
    \draw (\x,-.2) -- (\x,.2);
    \draw[loosely dotted] (\x,.2) -- (\x,\alto);
}
\foreach \tick in {0,\tix,...,\myend}{
    \draw (\tick,.1) -- (\tick,-.1);
}

\nation{11/2008}{10/2010}{1}{cyan}{Hungary}
\nation{12/2008}{12/2011}{2}{olive}{Latvia}
\nation{5/2009}{6/2011}{3}{gray}{Romania I}
\nation{5/2010}{6/2015}{4}{red}{Greece I \& II}
\end{tikzpicture}
\end{document}
Related Question