7

I want to use the chronology package to draw a timeline from 2011 until 2016 where each year should be a major tick and between each major tick, there should be 3 minor ticks.

I tried to implement this like this:

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

\end{chronology}
\end{document}

However, this ends up in a timeline like this:

output

How can I achieve the timeline I want?

4
  • Do you just need the timeline (I mean, would it be valid to produce the timeline without the chronology package) or are you planning to use other features from the chronology package? Feb 19, 2014 at 13:42
  • I'm planning to add a couple of events and time ranges. So yes, I need the chronology package. Feb 19, 2014 at 13:43
  • the phrase "where is year should be a major tick": do you mean "where each year should be a major tick"? Feb 19, 2014 at 14:45
  • Yes, I'm going to change taht. Feb 19, 2014 at 17:35

1 Answer 1

9

The original chronology environment doesn't allow this. Below I defined a markschronology environment which behaves in a similar fashion to chronology (it has the same arguments and it was defined following the original definition) and allows you to specify a number of intermediate ticks; the number of intermediate ticks is controlled by \Marks with default value 0 (i.e., no intermediate ticks):

\documentclass{article}
\usepackage{chronology}

\def\Marks{0}

\makeatletter
\def\@marks{}
\newenvironment{markschronology}
  {%
    \@ifstar{\chronology@startrue\markschronology@i*}  {\chronology@starfalse\markschronology@i*}%
  }
  {%
    \end{tikzpicture}%
    \end{lrbox}%
    \raisebox{2ex}{%
      \resizebox{\timelinewidth}{!}{\usebox{\timelinebox}}%
    }%
  }

\def\markschronology@i*{%
    \@ifnextchar[{\markschronology@ii*}{\markschronology@ii*[{5}]}%
}

\def\markschronology@ii*[#1]#2#3#4{%
    \@ifnextchar[{\markschronology@iii*[{#1}]{#2}{#3}{#4}}{\markschronology@iii*[{#1}]{#2}{#3}{#4}[{#4}]}%
}

\def\markschronology@iii*[#1]#2#3#4[#5]{%
  \newif\ifflipped%
  \ifchronology@star%
    \flippedtrue%
  \else%
    \flippedfalse%
  \fi%
  \setcounter{step}{#1}%
  \setcounter{yearstart}{#2}\setcounter{yearstop}{#3}%
  \setcounter{deltayears}{\theyearstop-\theyearstart}%
  \setlength{\unit}{#5/\thedeltayears}%
  \setlength{\timelinewidth}{#4}%
  \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,-0.1\unit) -- (0,0.1\unit);%
    }
    \pgfmathsetmacro{\@marks}{1+(1/(\Marks+1))}
    \foreach \x in {1,\@marks,...,\thedeltayears}
    {
      \draw[xshift=\x*\unit] (0,-0.05\unit) -- (0,0.05\unit);%
    }
    \addtocounter{deltayears}{1}%
    \foreach \x in {\thestepstart,\thestep,...,\thestepstop}
    {%
      \pgfmathsetlength\xstop{(\x-\theyearstart)*\unit}%
      \ifflipped%
        \node at (\xstop,0) [above=.2\unit] {\x};%
      \else%
        \node at (\xstop,0) [below=.2\unit] {\x};%
      \fi%
    }%
}
\makeatother

\begin{document}

\noindent\begin{markschronology}[1]{2010}{2016}{\textwidth}
\end{markschronology}\par\bigskip

\def\Marks{3}
\noindent\begin{markschronology}[1]{2010}{2016}{\textwidth}
\end{markschronology}\par\bigskip

\def\Marks{5}
\noindent\begin{markschronology}[1]{2010}{2016}{\textwidth}
\end{markschronology}

\end{document}

enter image description here

13
  • 1
    Could you write, whether the original package is able to do this or not(and thereby justifying your hard work:o) Feb 19, 2014 at 15:06
  • @Hans-PeterE.Kristiansen done! :) Feb 19, 2014 at 15:08
  • Sounds great. When I compile your code I get the following error: ! Undefined control sequence. \reserved@c ->\chronology@starfalse \markschronology@i * l.70 \noindent\begin{markschronology}[ 1]{2010}{2016}{\textwidth} ? Feb 19, 2014 at 17:42
  • @RoflcoptrException Are you using updated versions of the packages? If you compile just my example code exactly as it is, do you still get the same error message? Feb 19, 2014 at 18:01
  • @GonzaloMedina That's exactly what I did, I copied all your code and compiled it. Feb 19, 2014 at 18:34

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.