# How do I create a timeline charts similar to this style? Suggestions

I would like to reproduce a lot of time line charts with a style similar to the image below.

The charts would show how different events in history are related to each other in time.

I would like to also include text to the left of each row as well for the event plotted on the timeline.

I’ve never used Tikz, (or pgfgantt). Would this be difficult to create with LaTeX code with one of these ?

Here is an automated solution. Define a new command called \timeline that has 6 arguments, one optional. The syntax is

\timeline[<eventspace>]{<label>}{<start>}{<step>}{<number>}{<intervals>}

<label> is "A.D." in your example. <start> is the start year after <label>: 30 in your example. <step> is the number of years between labeled years: 5 in your example. <number> is the number of labeled years, which is 11 in your example.

<eventspace> is the length (in cm) allotted for the events on the left. The default is 2.

<intervals> is a comma separated list where each entry has the form begin/end/event. event can be empty.

For example, the code

\timeline[2.5]{A.D.}{30}{5}{11}{29/33/event 1,32/34.5/event 2,35.5/38/something,44/48/??,45.5/48/X,47/49.5/Y,47.5/52/Z,52/57.5/,61.5/63/,64/67/A}


produces the output

Here is the complete code:

\documentclass{article}

\usepackage{tikz}
\definecolor{linecolor}{rgb}{0, 0.5, 0.5}

\newcommand{\timeline}[6][2]{\begin{tikzpicture}
\node[anchor=base] at (0,.15){\textsf{\textbf{\scriptsize#2}}};
\foreach [var=\n, evaluate=\n as \l using int(\n*#4+#3-#4)] in {1,...,#5}{
\node[anchor=base] at (\n,.15){\textsf{\textbf\l}};}
\foreach [var=\timea, var=\timeb, var=\event, count=\n] in {#6}{
\pgfmathsetmacro{\col}{\ifodd\n"linecolor"\else"white"\fi}
\fill[color=\col!15](-#1,-\n+1) rectangle (#5+1,-\n);
\foreach \m in {0,...,#5}{\draw[linecolor](\m,-\n+1)--(\m,-\n);}
\fill[linecolor,rounded corners=1.5mm]({(\timea-#3+#4)/#4},-\n+.65) rectangle ({(\timeb-#3+#4)/#4},-\n+.35);
\node[anchor=base, right] at (-#1,-\n+.5) {\textsf{\textbf\event}};}
\draw[linecolor](-#1,0)--(#5+1,0);
\foreach [var=\timea, var=\timeb, count=\n] in {#6}{\draw[linecolor](-#1,-\n)--(#5+1,-\n);}
\end{tikzpicture}}
%\timeline{label}{start}{step}{number}{intervals}

\begin{document}

\timeline[2.5]{A.D.}{30}{5}{11}{29/33/event 1,32/34.5/event 2,35.5/38/something,44/48/??,45.5/48/X,47/49.5/Y,47.5/52/Z,52/57.5/,61.5/63/,64/67/A}

\end{document}

• Wow @Sandy G !!! Perfect!!! I'm blown away !!! This perfectly answered my question !!! (Excellent colors too!!). How do I give you credit for this answer ? (I'll study what you've done here ... is it easy to make modifications whereby the row labels are also included into the alternating colored rows ? This is awesome. I'm going to have to learn Tikz Jan 3 at 14:56
• Yes, it's an easy modification. I'll edit my response shortly. Jan 3 at 16:00
• Thank you so very much !!! I am going after left-justified text within a "first column" of the chart - if possible. I would have included the complete pic if it were not for copyright issues. ( I am learning by making some basic modifications - afterwards ... I'll read the manual ... lol). I have no problem donating a nice tip for a cup of coffee ! Jan 3 at 16:32
• I edited my response. As for credit, if you are writing a paper or book you can include my name (Sandy Ganzell) in an acknowledgement/footnote/endnote if you wish, but it is not necessary. My post here is public and can be used freely without credit (except within this site, see this help page). Jan 3 at 19:39
• Perfect !!! Thank You ! Jan 3 at 19:47

Using pgfgantt:

Edit: the best I could come up with for now is this:

\documentclass{standalone}
\usepackage{pgfgantt}
\begin{document}
\begin{ganttchart}[hgrid, vgrid]{30}{84}
\gantttitlelist[
title/.append style=
]{30,35,...,80}{5} \\
\ganttbar{}{30}{33}\ganttnewline
\ganttbar{}{33}{34}\ganttnewline
\ganttbar{}{36}{36}\ganttnewline
\ganttbar{}{44}{46}\ganttnewline
\ganttbar{}{46}{46}\ganttnewline
\end{ganttchart}
\end{document}


I know this is not quite what you are looking for but I hope it will help.

• I saw this package. Very nice. If the time labels are in units of 10s … I.e 20, 30, 40, 50, etc. Is there a way to refine the marks to precision? Like from 44 to 52? This looked like it may be limited to the exact boundaries, which would defeat the purpose. This would be great if it were not limited to the exact boundaries. Jan 1 at 17:49