5

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.

  • @LaRiFaRi That produced a tiny timeline without the years. – P. de Rijke Mar 18 '15 at 12:33
2

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}
| improve this answer | |
  • That does it! I had tried leaving the curly braces around "3ex" empty, but hadn't tried you solution. – P. de Rijke Mar 18 '15 at 12:35
  • It is still strange that the code in my MWE does compile for others... – P. de Rijke Mar 18 '15 at 12:37
  • My only guess is that the package has been updated without changing the version info. It is very short on documentation... – Andrew Swann Mar 18 '15 at 13:40
1

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

| improve this answer | |
  • 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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.