I'm trying to display a timeline in my document using the package chronology, however it does weird things.

I'm using the following code:

\begin{chronology}[5]{0}{30}{4ex}{\textwidth}
\event[0]{2}{$P_5$} % 2
\event[2]{3}{\color{gray}switch}
\event[3]{5}{$P_4$} % 2
\event[5]{6}{\color{gray}switch}
\event[6]{8}{$P_3$} % 2
\event[8]{9}{\color{gray}switch}
\event[9]{11}{$P_2$} % 2
\event[11]{12}{\color{gray}switch} %%%%%% gap
\event[12]{14}{$P_1$} % 2
\event[14]{15}{\color{gray}switch}
\event[15]{16}{$P_5$} % 1
\event[16]{17}{\color{gray}switch}
\event[17]{19}{$P_4$} % 2
\event[19]{20}{\color{gray}switch}
\event[20]{22}{$P_2$} % 2
\event[22]{23}{\color{gray}switch} %%%%%% gap
\event[23]{25}{$P_1$} % 2
\event[25]{26}{\color{gray}switch}
\event[26]{28}{$P_4$} % 2
\event[28]{29}{\color{gray}switch}
\event[29]{30}{$P_1$} % 1
\end{chronology}


This should produce a completely filled timeline, but there are two gaps as seen in the picture linked below. What could be the problem?

Screenshot:

-
Welcome to TeX.sx! –  Sean Allred Apr 18 '13 at 13:00

The package is buggy. Inside the chronology environment some counters and lengths are defined, so using it more than once will trigger errors. Also, the \event command has a conditional in the form \ifx #1e...\else...\fi which doesn't seem to do what the author expected and was responsible for the odd behaviour.

In the following code I took care of the problem with the multiple definition of lengths and counters (removing them from the environment) and also suppressed the conditional. These changes seem to fix the problem, but the best thing to do would be to contact the package author.

With the modification is necessary to always use the optional argument for \event.

\documentclass{article}
\usepackage{chronology}

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

\renewenvironment{chronology}[5][5]{%
\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}}}}%
\renewcommand{\event}[3][e]{%
\pgfmathsetlength\xstop{(#2-\theyearstart)*\unit}%
\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);%
}%

\begin{document}

\noindent\begin{chronology}[5]{0}{30}{3ex}{\textwidth}
\event[0]{2}{$P_5$} % 2
\event[2]{3}{\color{gray}switch}
\event[3]{5}{$P_4$} % 2
\event[5]{6}{\color{gray}switch}
\event[6]{8}{$P_3$} % 2
\event[8]{9}{\color{gray}switch}
\event[9]{11}{$P_2$} % 2
\event[11]{12}{\textcolor{gray}{switch}} %%%%%% gap
\event[12]{14}{$P_1$} % 2
\event[14]{15}{\color{gray}switch}
\event[15]{16}{$P_5$} % 1
\event[16]{17}{\color{gray}switch}
\event[17]{19}{$P_4$} % 2
\event[19]{20}{\color{gray}switch}
\event[20]{22}{$P_2$} % 2
\event[22]{23}{\color{gray}switch} %%%%%% gap
\event[23]{25}{$P_1$} % 2
\event[25]{26}{\color{gray}switch}
\event[26]{28}{$P_4$} % 2
\event[28]{29}{\color{gray}switch}
\event[29]{30}{$P_1$} % 1
\end{chronology}

\end{document}


-
Thank you very much. I will contact the author as soon as I get to it.. –  henrik Apr 18 '13 at 13:37