6

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. 
to be read again> 
} 
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.

2 Answers2

3

Removing the 3ex produces the following output without error:

Sample output

\documentclass{article}
\usepackage{chronology}
\begin{document}
\begin{chronology}[3]{2011}{2016}{\textwidth}
\end{chronology}
\end{document}
Andrew Swann
  • 95,762
2

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)}%
    \addtocounter{step}{\thestepstart}%
    \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);%
    \addtocounter{deltayears}{1}%
    \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}

enter image description here

LaRiFaRi
  • 43,807
  • 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. – P. de Rijke Mar 18 '15 at 14:53
  • What should do if I want something like: 100 --- 150 --- 200 ---- 250 --- 300 -----350 --- ... – alper Feb 22 '21 at 13:22