Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I wanted to create a document that contains multiple timelines on one page. I am using chronology.sty, which uses TikZ, to accomplish this. However, I get an error when I try to create more than one timeline in a document. Here's a block that works and it creates a document with a single timeline:

\documentclass{article}
\usepackage{chronology}
\begin{document}
\begin{chronology}[2]{2000}{2012}{5ex}{\textwidth}
\event{2004}{single event}
\event[2007]{2009}{Multi-year event}
\end{chronology}
\end{document}

But now I want to add another timeline underneath the above:

\documentclass{article}
\usepackage{chronology}
\begin{document}
\begin{chronology}[2]{2000}{2012}{5ex}{\textwidth}
\event{2004}{single event}
\event[2007]{2009}{Multi-year event}
\end{chronology}

\begin{chronology}[2]{2000}{2012}{5ex}{\textwidth}
\event{2002}{single event 2}
\event[2006]{2008}{Multi-year event 2}
\end{chronology}
\end{document}

This produces the error:

! LaTeX Error: Command \c@step already defined

It appears the problem is caused by a counter variable that chronology.sty creates:

\newcounter{step}

Is the error that every time I create a chronology environment, LaTeX tries to re-define 'step'? If so, how do I get around this?

EDIT: I made an error copying my code over here. My first chronology environment IS properly closed, and I still get the error. Apologies for the typo.

share|improve this question
add comment

2 Answers

up vote 10 down vote accepted

The chronology package defines a number of counters, lengths and boxes within the chronology environment. That means these lengths/boxes already exist after the first use of \begin{chronology}...\end{chronology}, causing an error when you use it a second time. Removing the offending \newcounter, \newlength and \newsavebox definitions from \newenvironment{chronology} in the .sty file fixes this:

\newcounter{step}\newcounter{stepstart}\newcounter{stepstop}%
\newcounter{yearstart}\newcounter{yearstop}\newcounter{deltayears}%
\newlength{\xstart}\newlength{\xstop}%
\newlength{\unit}\newlength{\timelinewidth}%
\newsavebox{\timelinebox}%

Now, compiling your MWE, it produces the correct result without error.

\documentclass{article}
\usepackage{chronology}
\begin{document}
\begin{chronology}[2]{2000}{2012}{5ex}{\textwidth}
\event{2004}{single event}
\event[2007]{2009}{Multi-year event}
\end{chronology}% Inserted this missing environment \end

\begin{chronology}[2]{2000}{2012}{5ex}{\textwidth}
\event{2002}{single event 2}
\event[2006]{2008}{Multi-year event 2}
\end{chronology}
\end{document}

enter image description here

This error is not fatal for compiling your document. You can skip over (or ignore) these errors, and TeX should still produce the desired output. However, I would suggest contacting the package author and requesting an update my modifying/correcting this behaviour since it is fairly simple. Some commands obey scoping rules; in this case the definition was global. For completeness, here's the new, updated chronology.sty:

%%
%% This is file `chronology.sty',
%% generated with the docstrip utility.
%%
%% The original source files were:
%%
%% chronology.dtx  (with options: `package')
%% 
%% This is a generated file.
%% 
%% Copyright (C) 2010 by Levi Wiseman
%% 
%% This work may be distributed and/or modified under the
%% conditions of the LaTeX Project Public License, either version 1.3
%% of this license or (at your option) any later version.
%% The latest version of this license is in
%%   http://www.latex-project.org/lppl.txt
%% and version 1.3 or later is part of all distributions of LaTeX
%% version 2005/12/01 or later.
%% 
%% This work has the LPPL maintenance status `maintained'.
%% 
%% The Current Maintainer of this work is Levi Wiseman.
%% 
%% This work consists of the file chronology.dtx and the derived files
%% chronology.ins, chronology.pdf, and chronology.sty.
%% 
\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{chronology}[2010/6/12 v1.0 Horizontal timeline]
\RequirePackage{calc}
\RequirePackage{tikz}
\RequirePackage{ifthen}

% MOVED NEW DEFINITIONS (COUNTERS/LENGTHS/BOXES)
  \newcounter{step}\newcounter{stepstart}\newcounter{stepstop}%
  \newcounter{yearstart}\newcounter{yearstop}\newcounter{deltayears}%
  \newlength{\xstart}\newlength{\xstop}%
  \newlength{\unit}\newlength{\timelinewidth}%
  \newsavebox{\timelinebox}%
\newenvironment{chronology}[5][5]{%
  %\newcounter{step}\newcounter{stepstart}\newcounter{stepstop}%
  %\newcounter{yearstart}\newcounter{yearstop}\newcounter{deltayears}%
  %\newlength{\xstart}\newlength{\xstop}%
  %\newlength{\unit}\newlength{\timelinewidth}%
  \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}%
  %\newsavebox{\timelinebox}%
  \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}}}}%
\newcommand{\event}[3][e]{%
  \pgfmathsetlength\xstop{(#2-\theyearstart)*\unit}%
  \ifx #1e%
    \draw[fill=black,draw=none,opacity=0.5]%
      (\xstop, 0) circle (.2\unit)%
      node[opacity=1,rotate=45,right=.5\unit] {#3};%
  \else%
    \pgfmathsetlength\xstart{(#1-\theyearstart)*\unit}%
    \draw[fill=black,draw=none,opacity=0.5,rounded corners=.2\unit]%
      (\xstart,-.2\unit) rectangle%
      node[opacity=1,rotate=45,right=.5\unit] {#3} (\xstop,.2\unit);%
  \fi}%
\newcommand{\decimaldate}[3]{(#1-1)/31/12+(#2-1)/12+#3}
\endinput
%%
%% End of file `chronology.sty'.
share|improve this answer
    
Perfect. Thanks! –  Mike Wierzbicki Oct 14 '11 at 19:31
    
This helped me! Nice answer. +1! –  Alenanno Mar 30 '12 at 17:30
add comment

You must have one \end{chronology} for each \begin{chronology}.

\documentclass{article}
\usepackage{chronology}
\begin{document}

\begin{chronology}[2]{2000}{2012}{5ex}{\textwidth}
\event{2004}{single event}
\event[2007]{2009}{Multi-year event}
\end{chronology}

\begin{chronology}[2]{2000}{2012}{5ex}{\textwidth}
\event{2002}{single event 2}
\event[2006]{2008}{Multi-year event 2}
\end{chronology}

\end{document}

I don't have the opportunity to test the code, but I think it will work.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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