While browsing tex.SE I saw this answer here and was really surprised at how nice and clean it looked. Now I'm facing a slightly different problem and I'm not really familiar with tikz (I only know how to do some simple stuff) so I couldn't really adapt the code to fit my problem.
Assuming you have one A4 page of space, I'd like to divide one timeline into 13 separate "sublines", each "subline" representing one month and beginning on a new line on the paper. Then create a colored square for every event on the timeline and write the name of the event in that square.
To make it maybe a little bit clearer here is an image.
The goal would be to create a new command, similar to the post mentioned, with the following information:
\event{dd.mm.}{dd.mm.}{text}{color}{number}
Where the first argument would be the starting date of the event, and the second one the ending date. The third argument should represent the text inside the square, the fourth argument is the color of the square and since some of the events overlap I would also need the option to place the events at different heights, therefore the last argument.
The two biggest problems for me here are:
- I don't know how to create one, continuous line and than split it into thirteen pieces, each on a new line.
- There are some events that are only one day long, so there is no chance that the text would fit there. These cases then would need some special treatment, but I don't know how one could implement something like that.
Alternatively I'd also be fine with creating thirteen timelines separately and then putting them together in a single picture, with this at least the first problem would be solved. There was of course also the option of just creating this straight forward, with drawing an arrow as timeline, and each square, text, etc. by hand, but since the entries are probably going to change a lot in the future this seemed suboptimal.
I'm sorry for not having a working MWE, but I'm honestly a bit lost here at how to approach creating such an command.
EDIT: After some trying out I came up with the following:
\documentclass[12pt]{article}
\usepackage[a4paper, margin=1cm]{geometry}
\usepackage{amsmath}
\usepackage{xstring}
\usepackage{tikz}
\usetikzlibrary{fit, calc}
\pagestyle{empty}
\newcommand{\anno}{1} % starting year
\newcommand{\target}{31} % ending year
\newcommand{\alto}{3} % height
\pgfmathsetmacro{\myend}{\target+1-\anno}
\pgfmathsetmacro{\myspacing}{16/(\target-1-\anno)}
\newcommand{\eventpoint}[4]{
\StrBefore{#1}{/}[\dstart]%x1=day_start
\StrBehind{#1}{/}[\mstart]%y1=month_start
\StrBefore{#2}{/}[\dend]%x2=day_end
\StrBehind{#2}{/}[\mend]%y2=month_end
\pgfmathsetmacro{\mmstart}{((13-\mstart)*4)}
\pgfmathsetmacro{\mmend}{((13-\mend)*4)}
\ifthenelse{\mstart = \mend}
{\filldraw[fill=#3!50, draw=#3,] (\dstart, \mmstart ) rectangle (\dend, \mmend+1) node [font=\scriptsize, text centered, midway, inner sep=0pt] {#4};}
{\filldraw[fill=#3!50, draw=#3,] (\dstart, \mmstart ) rectangle (31, \mmstart+1) node [font=\scriptsize, text centered, midway, inner sep=0pt] {#4};
\filldraw[fill=#3!50, draw=#3,] (0, \mmend ) rectangle (\dend, \mmend+1) node [font=\scriptsize, text centered, midway, inner sep=0pt] {#4};};
}
\begin{document}
\begin{tikzpicture}[x=\myspacing cm,y=5mm]
\centering
%creating the sublines needed and formating them
\foreach \y in {0,4,8,12,16,20,24,28,32,36,40,44,48}{
\draw[|->, -latex] (-.5,\y) -- (\myend+.5,\y);
\path (0,0) -- (0,\alto);
\foreach \x [evaluate=\x as \day using int(\x)] in {0,10,20,30}{
\draw (\x,\y) node[below=7pt,font=\footnotesize] {$\day$};
\draw (\x,\y -.2) -- (\x,\y +.2);
\draw[loosely dotted] (\x,\y +.2) -- (\x,\y+ \alto-0.5);
}
\foreach \tick in {0,...,\myend}{
\draw (\tick,\y +.1) -- (\tick,\y -.1);
}
}
%trying to add the events
\eventpoint{15/7}{25/7}{green}{test}
\eventpoint{17/8}{19/9}{red}{test 2}
\end{tikzpicture}
\end{document}
The code is not working, but I suspect this is due to my wrong usage of \ifthenelse
. Hope someone could fix maybe that.
\ifnum\mstart=\mend ... \else ... \fi
, you don't need\ifthenelse
for this kind of condition...