# Creating a timeline with chronology

I am trying to create a simple timeline with years underneath the line and some explaining text above each year. I understand that chronology is useful for this.

My problem is that when trying out examples from related questions (e.g. here or here), I always get the error "! Missing number, treated as zero."

A MWE (from the first related question linked to above):

\documentclass{article}
\usepackage{chronology}
\begin{document}
\begin{chronology}[3]{2011}{2016}{3ex}{\textwidth}
\end{chronology}
\end{document}


Which results in:

! Missing number, treated as zero.
}
l.4 ...chronology}[3]{2011}{2016}{3ex}{\textwidth}
?


I have tried changing some of the values or removing them altogether, but this doesn't seem to help.

Has anyone encountered this problem or does anyone know of a solution? Chronology seems to be exactly what I need.

• @LaRiFaRi That produced a tiny timeline without the years. Mar 18, 2015 at 12:33

Removing the 3ex produces the following output without error:

\documentclass{article}
\usepackage{chronology}
\begin{document}
\begin{chronology}[3]{2011}{2016}{\textwidth}
\end{chronology}
\end{document}

• That does it! I had tried leaving the curly braces around "3ex" empty, but hadn't tried you solution. Mar 18, 2015 at 12:35
• It is still strange that the code in my MWE does compile for others... Mar 18, 2015 at 12:37
• My only guess is that the package has been updated without changing the version info. It is very short on documentation... Mar 18, 2015 at 13:40

The package has been changed after Oct 14 '11 (edit: or even Apr 18 '13) as the counters and lengths have been moved outside the environment definition. I do not know, why the CTAN is telling differently. Maybe it was happening both (Werner's post and Levi's fix) at more or less the same time.

However, the actual code does not provide the fixed definition of the chronology environment, which can be found here, too.

Using Werner's and Gonzalo's code, you get the image of the other post you have linked to.

% arara: pdflatex

\documentclass{article}
\usepackage{chronology}

\renewenvironment{chronology}[5][6]{%
\setcounter{step}{#1}%
\setcounter{yearstart}{#2}\setcounter{yearstop}{#3}%
\setcounter{deltayears}{\theyearstop-\theyearstart}%
\setlength{\unit}{#4}%
\setlength{\timelinewidth}{#5}%
\pgfmathsetcounter{stepstart}%
{\theyearstart+\thestep-mod(\theyearstart,\thestep)}%
\pgfmathsetcounter{stepstop}{\theyearstop-mod(\theyearstop,\thestep)}%
\begin{lrbox}{\timelinebox}%
\begin{tikzpicture}[baseline={(current bounding box.north)}]%
\draw [|->] (0,0) -- (\thedeltayears*\unit+\unit, 0);%
\foreach \x in {1,...,\thedeltayears}%
\draw[xshift=\x*\unit] (0,-.1\unit) -- (0,.1\unit);%
\foreach \x in {\thestepstart,\thestep,...,\thestepstop}{%
\pgfmathsetlength\xstop{(\x-\theyearstart)*\unit}%
\draw[xshift=\xstop] (0,-.3\unit) -- (0,.3\unit);%
\node at (\xstop,0) [below=.2\unit] {\x};}%
}
{%
\end{tikzpicture}%
\end{lrbox}%
\raisebox{2ex}{\resizebox{\timelinewidth}{!}{\usebox{\timelinebox}}}}%

\begin{document}
\noindent
\begin{chronology}[3]{2011}{2016}{3ex}{\textwidth}
\end{chronology}
\end{document}


• Thank you. That worked in the example, but curiously not when I started adding /events. I still got it to work with the answer I accepted above, but with different problems. I've asked a follow-up question. Mar 18, 2015 at 14:53
• What should do if I want something like: 100 --- 150 --- 200 ---- 250 --- 300 -----350 --- ... Feb 22, 2021 at 13:22