4

Can tikz chronology.sty be used to create a timeline such as year-quarter. That is with 0.25 intervals between the integer years. For example, 2002 2002.25, 2002.5, 2002.75, 2003,... (or 2002Q1, 2002Q2, ...) I tried changing the parameter [7] to [7.25] etc. but didnt have much luck. Any thoughts? MWE below

 \begin{chronology}[7]{2002}{2016}{3ex}{\textwidth}

The full code where I use the above statement is below.

\documentclass[11pt]{article}
\usepackage{chronology}

\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)}%
  \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}}}}%
\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}
    \begin{figure}[htbp]\centering
    \noindent\begin{chronology}[7]{2002}{2016}{3ex}{\textwidth}
    \end{chronology}
    \end{figure}
\end{document}
  • You are loading the package and then redefining pretty much everything? – cfr Jan 17 '17 at 3:25
  • You need to get rid of the use of counters where you want to be able to use fractions because counters can only be integers. Or use chronos, but you probably don't want to do that .... (I'd use chronos ....) Actually, I don't know whether chronos can do this, but I'm sure it could if anybody wanted it to. – cfr Jan 17 '17 at 3:45
  • Or maybe not ... :( – cfr Jan 17 '17 at 4:05
  • 1
    But I don't get it. Correct me if I'm wrong: you want to have empty small ticks for every quarter of an year, empty big ticks for every year and big labeled tikz (e.g. 2002) for every seven years? Is that it? – Guilherme Zanotelli Jan 17 '17 at 8:45
  • @GuilhermeZanotelli Oh, I thought the OP wanted labels for the ticks, too e.g. 2002.25 or 2002Q1 or whatever. Although the diagram would get rather large rather quickly. Or rather squashed. – cfr Jan 17 '17 at 13:15
5

Well, this chronology package has none to extremely little documentation. So I think it's better to draw it yourself. I made a command with some styles:

\drawtimeline[tikz options]{from year}{to year}{size};

So you can do

\documentclass[margin=5mm]{standalone}
\usepackage{tikz}
\usetikzlibrary{arrows.meta}% Unecessary (only here for the second example)
\usepackage{mychronology}% Code for this "pkg" is below

\begin{document}
    \begin{tikzpicture}[event/.style={very thick, solid, line cap=round}]
        \drawtimeline[%
            gray,
            timeline style={thick},
            labeled years step=6,
            minor tick step=0.25]{2002}{2016}{10cm};
        \drawtimeline[
            yshift=-2cm,
            labeled years step=2,
            timeline style={-stealth, shorten <=-5pt, very thick},
            year tick style={{Triangle[reversed,scale=0.75]}-, tick size=5pt,yshift=2.5pt},
            minor tick style={tick size=2pt, yshift=1pt},
            year label style={anchor=west, rotate=60,
                              outer sep=2pt, yshift=4pt}]{2002}{2016}{10cm};
         \draw[event, red] (Y-2002-2) -- (Y-2003);
    \end{tikzpicture}
\end{document}

enter image description here

The command creates coordinates like (Y-YEAR) and (Y-YEAR-MINORDIVISION) If any Event is to be shown in the middle of the timeline. Also several styles are available for customizations:

timeline style % Appends to the style 'timeline'
year label style % Appends to the style 'year label'
year tick style % Appends to the style 'year tick'
minor tick style % Appends to the style 'minor tick'
tick size % Sets the tick size (to be used inside 'year tick' and 'minor tick'
labeled years step % Sets the step between labeled years
minor tick step % Sets the step of ticks between years
year tick step % Sets the step of year ticks
enlarge timeline % Enlarges the arrow side of the timeline

Furthermore, the timeline is drawn inside a scope which receives the Options given to \drawtimeline, so if some key is passed directly to \drawtimeline it will be applied to all path specifications, for local customizations use the appropriate styles.

Complete MWE

\documentclass[margin=5mm]{standalone}
\usepackage{tikz}
\usetikzlibrary{arrows.meta}% Unecessary (only for the second example)

\tikzset{
  timeline/.style={-latex}%
  ,timeline style/.style={timeline/.append style={#1}}%
  ,year label/.style={below}%
  ,year label style/.style={year label/.append style={#1}}%
  ,year tick/.style={tick size=5pt}%
  ,year tick style/.style={year tick/.append style={#1}}%
  ,minor tick/.style={tick size=2pt, very thin}%
  ,minor tick style/.style={minor tick/.append style={#1}}%
  ,tick size/.code={\def\ticksize{#1}}%
  ,labeled years step/.code={\def\yearlabelstep{#1}}%
  ,minor tick step/.code={\def\minortickstep{#1}}%
  ,year tick step/.code={\def\yeartickstep{#1}}%
  ,enlarge timeline/.code={\def\enlarge{#1}}
}
\newcommand*{\drawtimeline}[4][]{%
  \def\fromyear{#2}%
  \def\toyear{#3}%
  \def\timelinesize{#4}%
  \pgfmathsetmacro{\timelinesizept}{\timelinesize}
  \begin{scope}[x=1pt, y=1pt, % Change main units to pt
                labeled years step=1,% Set some defaults
                minor tick step=0.25,%
                enlarge timeline=1.05,%
                year tick step=1,#1]
    \pgfmathsetmacro{\yearticksep}{\timelinesize/((\toyear-\fromyear)/\yeartickstep)}
    \pgfmathsetmacro{\minorticksep}{\timelinesize/((\toyear-\fromyear)/\minortickstep)}
    \pgfmathsetmacro{\minorticklast}{\minorticksep/\minortickstep)}
    \foreach \y[remember=\y as \lasty (initially 0), count=\i from \fromyear] in {0,\yearticksep,...,\timelinesizept}{
        \coordinate (Y-\i) at (\y,0);
        \draw[year tick] (\y,-\ticksize/2) --  ++(0,\ticksize);
        \ifnum\i=\toyear\breakforeach\else
        \foreach \q[count=\j from 0] in {0,\minorticksep,...,\minorticklast}{
            \coordinate (Y-\i-\j) at (\q+\y,0);
            \draw[minor tick] (\q+\y,-\ticksize/2) -- ++(0,\ticksize);
        };\fi
    };

    \pgfmathsetmacro{\nextyear}{int(\fromyear+\yearlabelstep)}
    \foreach \y in {\fromyear,\nextyear,...,\toyear} \node[year label] at (Y-\y) {\y};
    \draw[timeline] (0,0) -- +(\enlarge*\timelinesizept,0);% Timeline
  \end{scope}%
}

\begin{document}
    \begin{tikzpicture}[event/.style={very thick, solid, line cap=round}]
        \drawtimeline[%
            gray,
            timeline style={thick},
            labeled years step=6,
            minor tick step=0.25]{2002}{2016}{10cm};
        \drawtimeline[
            yshift=-2cm,
            labeled years step=2,
            timeline style={-stealth, shorten <=-5pt, very thick},
            year tick style={{Triangle[reversed, scale=0.75]}-, tick size=5pt, yshift=2.5pt},
            minor tick style={tick size=2pt, yshift=1pt},
            year label style={anchor=west, rotate=60, outer sep=2pt, yshift=4pt}]{2002}{2016}{10cm};
         \draw[event, red] (Y-2002-2) -- (Y-2003);
    \end{tikzpicture}
\end{document}

Code for mychronology (not tested)

\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{mychronology}[2017/01/18 For timelines drawings]
\RequirePackage{tikz}
\tikzset{
  timeline/.style={-latex}%
  ,timeline style/.style={timeline/.append style={#1}}%
  ,year label/.style={below}%
  ,year label style/.style={year label/.append style={#1}}%
  ,year tick/.style={tick size=5pt}%
  ,year tick style/.style={year tick/.append style={#1}}%
  ,minor tick/.style={tick size=2pt, very thin}%
  ,minor tick style/.style={minor tick/.append style={#1}}%
  ,tick size/.code={\def\ticksize{#1}}%
  ,labeled years step/.code={\def\yearlabelstep{#1}}%
  ,minor tick step/.code={\def\minortickstep{#1}}%
  ,year tick step/.code={\def\yeartickstep{#1}}%
  ,enlarge timeline/.code={\def\enlarge{#1}}
}
\newcommand*{\drawtimeline}[4][]{%
  \def\fromyear{#2}%
  \def\toyear{#3}%
  \def\timelinesize{#4}%
  \pgfmathsetmacro{\timelinesizept}{\timelinesize}
  \begin{scope}[%
      x=1pt, y=1pt, % Change main units to pt
      labeled years step=1,% Set some defaults
      minor tick step=0.25,%
      enlarge timeline=1.05,%
      year tick step=1,#1]
    \pgfmathsetmacro{\yearticksep}{\timelinesize/((\toyear-\fromyear)/\yeartickstep)}
    \pgfmathsetmacro{\minorticksep}{\timelinesize/((\toyear-\fromyear)/\minortickstep)}
    \pgfmathsetmacro{\minorticklast}{\minorticksep/\minortickstep)}
      \foreach \y[remember=\y as \lasty (initially 0), count=\i from \fromyear] in {0,\yearticksep,...,\timelinesizept}{
      \coordinate (Y-\i) at (\y,0);
      \draw[year tick] (\y,-\ticksize/2) --  ++(0,\ticksize);
      \ifnum\i=\toyear\breakforeach\else
      \foreach \q[count=\j from 0] in {0,\minorticksep,...,\minorticklast}{
      \coordinate (Y-\i-\j) at (\q+\y,0);
      \draw[minor tick] (\q+\y,-\ticksize/2) -- ++(0,\ticksize);
      };\fi
    };
    \pgfmathsetmacro{\nextyear}{int(\fromyear+\yearlabelstep)}
    \foreach \y in {\fromyear,\nextyear,...,\toyear} \node[year label] at (Y-\y) {\y};
    \draw[timeline] (0,0) -- +(\enlarge*\timelinesizept,0);% Timeline
  \end{scope}%
}
\endinput
  • Nice. (Well, probably. I didn't actually compile it.) :-) – cfr Jan 18 '17 at 1:14
  • @crf, Now it's nice. Not nicer than using your chronos, but a little simpler maybe (I did it mostly for fun, as you can imagine...) :) – Guilherme Zanotelli Jan 18 '17 at 9:55
  • By the way, you have to get the f and the r the right way around to ping me ;). Definitely simpler. You should be careful, though - this is how chronos started. – cfr Jan 19 '17 at 0:13
  • Though since I'm the only one here, I get pinged anyhow. – cfr Jan 19 '17 at 0:16
4

Here's an example with chronos which has been specifically extended to provide at least rudimentary functionality of this kind.

Here are a couple of very basic examples:

\begin{tikzpicture}
  [
    chronos={%
      period/.style={draw=gray},
      start date=2002-01-01,
      end date=2016-12-31,
      timeline line={gray, -Latex},
      timeline marks,
      timeline minor marks,
      timeline mark={gray},
      timeline minor mark={gray},
      minor steps=4,
      timeline year={font=\tiny, fill=none},
      timeline margin=5mm,
      timeline width=90mm,
    }
  ]
\end{tikzpicture}

\begin{tikzpicture}
  [
    chronos={%
      period/.style={draw=gray},
      start date=2002-01-01,
      end date=2016-12-31,
      timeline line={darkgray, -Stealth},
      timeline marks,
      timeline minor marks,
      timeline mark={darkgray, ultra thick},
      timeline minor mark={darkgray, thick},
      minor steps=4,
      step years=2,
      timeline year={fill=none},
      timeline margin=5mm,
      timeline width=90mm,
      timeline year={text=darkgray, rotate=90},
      timeline years anchor=west,
    }
  ]
\end{tikzpicture}

chronos variations

The complete code is a little long as it is designed to do various other things, in addition to drawing the kind of timeline you requested. Hopefully, this will eventually make a good replacement for chronosys and chronology, but only time (and feedback) will tell.

Note that minor steps specifies the number of steps between the major markers. So, if you want 4 steps per year, but to only mark every other year as a major step, you should change the 4 to 8 in the second example.

\documentclass[border=10pt,tikz]{standalone}
\usepackage{pgfcalendar}
\usepackage{datenumber,xparse,fp}
\usetikzlibrary{arrows.meta,backgrounds,fixedpointarithmetic}
\makeatletter
\ExplSyntaxOn
\tl_new:N \l_chronos_date_tl
\tl_new:N \l_chronos_dateformat_tl
\tl_new:N \l_chronos_year_tl
\tl_new:N \l_chronos_yearformat_tl
\tl_set:Nn \l_chronos_dateformat_tl { !d/!m/!Y }
\tl_set:Nn \l_chronos_yearformat_tl { !Y }
% YY yn lle YYYY
\cs_new_protected_nopar:Npn \chronos_year_shorten:n #1
{
  \chronos_year_shorten_aux:w #1 \q_stop % expl3 manuaal, 46
}
\cs_new_protected_nopar:Npn \chronos_year_shorten_aux:w #1 #2 #3 #4 \q_stop
{
  #3 #4
}
\cs_generate_variant:Nn \chronos_year_shorten:n { V , c }
\cs_generate_variant:Nn \int_abs:n { c }
\cs_generate_variant:Nn \tl_replace_all:Nnn { Nnx }
% dangos dyddiadau
\cs_new_protected_nopar:Npn \chronos_show_date:n #1
{% ateb Joseph Wright: http://tex.stackexchange.com/a/327642/
  \tl_set_eq:NN \l_chronos_date_tl \l_chronos_dateformat_tl
  \tl_replace_all:Nnx \l_chronos_date_tl { !a } { \pgfcalendarweekdayshortname{\thechronos@weekday} }
  \tl_replace_all:Nnx \l_chronos_date_tl { !A } { \pgfcalendarweekdayname{\thechronos@weekday} }
  \tl_replace_all:Nnx \l_chronos_date_tl { !b } { \pgfcalendarmonthshortname{\csname chronos@#1month\endcsname} }
  \tl_replace_all:Nnx \l_chronos_date_tl { !B } { \pgfcalendarmonthname{\csname chronos@#1month\endcsname} }
  \tl_replace_all:Nnx \l_chronos_date_tl { !d } { \csname chronos@#1day\endcsname }
  \tl_replace_all:Nnx \l_chronos_date_tl { !E } { \chronos_dateformat_era:c { chronos@#1year } }
  \tl_replace_all:Nnx \l_chronos_date_tl { !m } { \csname chronos@#1month\endcsname }
  \tl_replace_all:Nnx \l_chronos_date_tl { !q } { \chronos_dateformat_sign:c { chronos@#1year } }
  \tl_replace_all:Nnx \l_chronos_date_tl { !Q } { \chronos_dateformat_signs:c { chronos@#1year } }
  \tl_replace_all:Nnx \l_chronos_date_tl { !y } { \chronos_year_shorten:c { chronos@#1year } }
  \tl_replace_all:Nnx \l_chronos_date_tl { !Y } { \int_abs:c { chronos@#1year } }
  \l_chronos_date_tl
}
\cs_new_protected_nopar:Npn \chronos_show_year:n #1
{% ateb Joseph Wright: http://tex.stackexchange.com/a/327642/
  \tl_set_eq:NN \l_chronos_year_tl \l_chronos_yearformat_tl
  \tl_replace_all:Nnx \l_chronos_year_tl { !E } { \chronos_dateformat_era:n { #1 } }
  \tl_replace_all:Nnx \l_chronos_year_tl { !q } { \chronos_dateformat_sign:n { #1 } }
  \tl_replace_all:Nnx \l_chronos_year_tl { !Q } { \chronos_dateformat_signs:n { #1 } }
  \tl_replace_all:Nnx \l_chronos_year_tl { !y } { \chronos_year_shorten:n { #1 } }
  \tl_replace_all:Nnx \l_chronos_year_tl { !Y } { \int_abs:n { #1 } }
  \l_chronos_year_tl
}
\cs_new_protected_nopar:Npn \chronos_dateformat_sign:n #1
{
  \int_compare:nT { #1 < 0 } { - }
}
\cs_generate_variant:Nn \chronos_dateformat_sign:n { c }
\cs_new_protected_nopar:Npn \chronos_dateformat_signs:n #1
{
  \int_compare:nTF
  { #1 < 0 } { - }
  {
    \int_compare:nT { #1 > 0 }
    {
      \ifchronos@yearzero\relax
      \else
        \int_compare:nT { #1 > 1} { +  }
      \fi
    }
  }
}
\cs_generate_variant:Nn \chronos_dateformat_signs:n { c }
\cs_new_protected_nopar:Npn \chronos_dateformat_era:n #1
{
  \int_compare:nTF
  { #1 < 0 } { \chronos@yearbce }
  {
    \int_compare:nT { #1 > 0 }
    {
      \ifchronos@yearzero\relax
      \else
        \int_compare:nT { #1 > 1} { \chronos@yearce }
      \fi
    }
  }
}
\cs_generate_variant:Nn \chronos_dateformat_era:n { c }
\cs_new_protected_nopar:Npn \chronos_set_dateformat:n #1
{
  \tl_set:Nn \l_chronos_dateformat_tl { #1 }
  \tl_replace_all:Nnn \l_chronos_dateformat_tl { ~ } { \c_space_token }
}
\cs_new_protected_nopar:Npn \chronos_set_yearformat:n #1
{
  \tl_set:Nn \l_chronos_yearformat_tl { #1 }
  \tl_replace_all:Nnn \l_chronos_yearformat_tl { ~ } { \c_space_token }
}
% user interface
\NewDocumentCommand \chronos@setdateformat { m }
{
  \chronos_set_dateformat:n { #1 }
}
\NewDocumentCommand \chronos@setyearformat { m }
{
  \chronos_set_yearformat:n { #1 }
}
% for pgf/tikz convenience
\NewDocumentCommand \chronos@showdate { o m }
{
  \group_begin:
    \IfValueT { #1 }
    {
      \chronos_set_dateformat:n { #1 }
    }
    \pgfcalendarjuliantoweekday{\csname thechronos@#2date\endcsname}{\c@chronos@weekday}%
    \chronos_show_date:n { #2 }
  \group_end:
}
\NewDocumentCommand \chronos@showyear { o m }
{
  \group_begin:
    \IfValueT { #1 }
    {
      \chronos_set_yearformat:n { #1 }
    }
    \chronos_show_year:n { #2 }
  \group_end:
}
\ExplSyntaxOff
\newlength\chronos@tempdima
\newcounter{chronos@date}
\newcounter{chronos@startdate}
\newcounter{chronos@enddate}
\newcounter{chronos@startyear}
\newcounter{chronos@endyear}
\newcounter{chronos@yeardate}
\newcounter{chronos@thingdate}
\newcounter{chronos@otherthingdate}
\newcounter{chronos@weekday}
\newcounter{chronos@tempcnta}
\newif\ifchronos@marks
\chronos@marksfalse
\newif\ifchronos@marks@minor
\chronos@marks@minorfalse
\newif\ifchronos@timeline@showyears
\chronos@timeline@showyearstrue
\newif\ifchronos@eventyearsonline
\chronos@eventyearsonlinefalse
\newif\ifchronos@yearzero
\chronos@yearzerofalse
\newif\ifchronos@onlytext
\chronos@onlytextfalse
\newif\ifchronos@markeras
\chronos@markerasfalse
\newif\ifchronos@yearsonline
\chronos@yearsonlinefalse
\newif\ifchronos@eventdatessplit
\chronos@eventdatessplitfalse
\pgfkeys{/pgf/number format,
  int detect,
  set thousands separator={},
}
\tikzset{%
  /handlers/.chronos too/.code={%
    \edef\chronos@tempc{\pgfkeyscurrentpath}%
    \edef\chronos@tempd{#1}%
    \tikzset{%
      \pgfkeyscurrentpath @too/.code={%
        \tikzset{%
          /chronos/\chronos@tempd/.append style={##1},
        }%
      },
      \chronos@tempc/.forward to=\chronos@tempc @too,
    }%
  },
  chronos/.code={% http://tex.stackexchange.com/a/159856/ - Claudio Fiandrino
    \tikzset{%
      align=center,
      anchor=mid,
      fixed point arithmetic,
      /chronos/.cd,
      #1,
      timeline config,
      timeline config/.code={},
    }%
    \ifnum\chronos@startyear=\chronos@endyear
      \tikzset{%
        /chronos/timeline no years,
      }%
    \fi
    \setlength\chronos@tempdima{\chronos@timelinemargin}%
    \ifchronos@markeras
      {%
        \chronos@timelinefont
        \pgfmathsetmacro\chronos@tempe{((width("\chronos@bce"))>(width("\chronos@ce"))) ? (width("\chronos@bce")) : (width("\chronos@ce"))}%
        \xdef\chronos@tempf{\chronos@tempe}%
      }%
      \addtolength\chronos@tempdima{\chronos@tempf pt}%
    \fi
    \pgfmathsetmacro\chronos@unit{(\chronos@width-2*\chronos@tempdima)/(\thechronos@enddate-\thechronos@startdate)}%
    \draw [/chronos/timeline@line, line width=\chronos@height] (-\chronos@tempdima,0) coordinate (chronos pre) -- +(\chronos@width,0) coordinate (chronos post);
    \coordinate (chronos base) at (0,-.5*\chronos@height);
    \coordinate (chronos top) at (0,.5*\chronos@height);
    \coordinate (chronos foot) at (0,{-.5*\chronos@height-\chronos@borderheight});
    \coordinate (chronos head) at (0,{.5*\chronos@height+\chronos@borderheight});
    \coordinate (chronos start) at (0,0);
    \coordinate (chronos end) at ([xshift=-\chronos@tempdima]chronos post);
    \ifdim\chronos@borderheight>0pt
      \fill [bottom color=chronos@borderinner, top color=chronos@borderouter] (chronos pre |- chronos head) rectangle (chronos post |- chronos top);
      \fill [top color=chronos@borderinner, bottom color=chronos@borderouter] (chronos pre |- chronos base) rectangle (chronos post |- chronos foot);
    \fi
    \ifchronos@timeline@showyears
      \pgfmathsetcounter{chronos@startyear}{\chronos@startyear}%
      \pgfmathsetcounter{chronos@endyear}{\chronos@endyear}%
      \def\tempa{none}%
      \ifx\chronos@stepfrom\tempa
        \def\tempa{01}%
        \ifx\chronos@startmonth\tempa
          \ifx\chronos@startday\tempa
            \else\stepcounter{chronos@startyear}%
          \fi
          \else\stepcounter{chronos@startyear}%
        \fi
      \else
        \pgfmathsetcounter{chronos@startyear}{\chronos@stepfrom}%
      \fi
      \def\tempa{12}%
      \def\tempb{31}%
      \ifx\chronos@endmonth\tempa
        \ifx\chronos@endday\tempb
          \stepcounter{chronos@endyear}%
        \fi
      \fi
      \ifnum\value{chronos@endyear}<\value{chronos@startyear}\setcounter{chronos@endyear}{\thechronos@startyear}\fi
      \pgfmathsetmacro\chronos@nextstep{int(((\thechronos@startyear+\chronos@stepyears)>\thechronos@endyear) ? \thechronos@endyear : (\thechronos@startyear+\chronos@stepyears))}%
      \ifchronos@yearzero\setcounter{chronos@tempcnta}{1}\else\setcounter{chronos@tempcnta}{0}\fi
      \foreach \b [evaluate=\b as \i using {((\b==0)&&(\thechronos@tempcnta==0)) ? 1 : int(\b)}, remember=\i as \ilast (initially \pi)] in {\thechronos@startyear,\chronos@nextstep,...,\thechronos@endyear} {%
        \ifnum\i=\ilast\relax
        \else
          \pgfcalendardatetojulian{{\i}-01-01}{\c@chronos@yeardate}%
          \ifchronos@yearzero\relax\else\ifnum0<\i\addtocounter{chronos@yeardate}{-366}\fi\fi
          \pgfmathsetmacro\chronos@tempa{(\thechronos@yeardate-\thechronos@startdate)*\chronos@unit}%
          \ifnum\b=\chronos@nextstep
            \ifchronos@marks@minor
              \pgfmathsetmacro\chronos@tempg{((\thechronos@yeardate-\thechronos@startdate)*\chronos@unit)/\chronos@minorsteps}%
              \global\let\chronos@tempg\chronos@tempg
            \fi
          \fi
          \ifchronos@yearsonline
            \node (chronos@year@\i) [/chronos/.cd, timeline@years, timeline year on line] at (\chronos@tempa pt,0) {\chronos@timelinefont\chronos@showyear{\i}};
            \ifchronos@marks
               \path [/chronos/timeline mark on line] (chronos@year@\i.south) -- (chronos@year@\i |- chronos base);
               \path [/chronos/timeline mark on line] (chronos@year@\i.north) --  (chronos@year@\i |- chronos top);
              \ifchronos@marks@minor
                \ifnum\ilast=\pi\relax
                \else
                  \foreach \m [evaluate=\m as \n using {\m-1}] in {2,...,\chronos@minorsteps}
                    \path [/chronos/timeline minor mark on line] ([xshift={-\n*\chronos@tempg pt}]chronos@year@\i.south) -- ([xshift={-\n*\chronos@tempg pt}]chronos@year@\i |- chronos base);
                    \path [/chronos/timeline minor mark on line] ([xshift={-\n*\chronos@tempg pt}]chronos@year@\i.north) --  ([xshift={-\n*\chronos@tempg pt}]chronos@year@\i |- chronos top);
                  \fi
              \fi
            \fi
            \ifchronos@markeras
              \path (chronos pre) +(\chronos@timelinemargin,0) node (chronos@bce) [/chronos/.cd, timeline@years, timeline year on line] {\chronos@timelinefont\chronos@bce};
              \path (chronos post) +(-\chronos@timelinemargin,0) node (chronos@ce) [/chronos/.cd, timeline@years, timeline year on line] {\chronos@timelinefont\chronos@ce};
            \fi
          \else
            \node (chronos@year@\i) [/chronos/.cd, timeline@years, timeline year off line] at (\chronos@tempa pt,0) {\chronos@timelinefont\chronos@showyear{\i}};
            \ifchronos@marks
              \path [shorten <=.5*\chronos@height, /chronos/timeline mark off line] (\chronos@tempa pt, 0) -- (chronos@year@\i) ;
              \ifchronos@marks@minor
                \ifnum\ilast=\pi\relax
                \else
                  \foreach \m  [evaluate=\m as \n using {int(\m-1)}] in {2,...,\chronos@minorsteps}
                    \path [shorten <=.5*\chronos@height, /chronos/timeline minor mark off line] ([xshift={-\n*\chronos@tempg pt}]\chronos@tempa pt,0) coordinate (\ilast-\n) -- (\ilast-\n |- chronos@year@\i.\chronos@timelineyearsanchor);
                  \fi
              \fi
            \fi
            \ifchronos@markeras
              \path (chronos pre) +(\chronos@timelinemargin,0) node (chronos@bce) [/chronos/.cd, timeline@years, timeline year off line] {\chronos@timelinefont\chronos@bce};
              \path (chronos post) +(-\chronos@timelinemargin,0) node (chronos@ce) [/chronos/.cd, timeline@years, timeline year off line] {\chronos@timelinefont\chronos@ce};
            \fi
          \fi
        \fi
      }%
    \else
      \ifchronos@markeras
        \path (chronos pre) +(\chronos@timelinemargin,0) node (chronos@bce) [/chronos/.cd, timeline@years, timeline year off line] {\chronos@timelinefont\chronos@bce};
        \path (chronos post) +(-\chronos@timelinemargin,0) node (chronos@ce) [/chronos/.cd, timeline@years, timeline year off line] {\chronos@timelinefont\chronos@ce};
      \fi
    \fi
    \ifchronos@eventyearsonline
      \tikzset{%
        /chronos/timeline years=on line,
      }%
    \fi
  },
  chronos set date/.code args={#1:#2:#3:#4}{%
    \pgfcalendardatetojulian{{#1}-#2-#3}{\c@chronos@date}%
    \setcounter{chronos@#4date}{\thechronos@date}%
    \ifchronos@yearzero\relax
    \else
      \setcounter{chronos@tempcnta}{#1}%
      \ifnum0<\value{chronos@tempcnta}%
        \addtocounter{chronos@#4date}{-366}%
      \fi
    \fi
    \expandafter\def\csname chronos@#4year\endcsname{#1}%
    \expandafter\def\csname chronos@#4month\endcsname{#2}%
    \expandafter\def\csname chronos@#4day\endcsname{#3}%
  },
  chronos date/.style args={#1-#2-#3}{%
    /tikz/chronos set date/.expanded={#1:#2:#3:thing}%
  },
  chronos period date/.style args={#1-#2-#3}{%
    /tikz/chronos set date/.expanded={#1:#2:#3:otherthing}%
  },
  /chronos/.search also={/tikz},
  /chronos/.cd,
  timeline config/.code={},
  date format/.code={%
    \chronos@setdateformat{#1}%
  },
  year format/.code={%
    \chronos@setyearformat{#1}%
  },
  step years/.store in=\chronos@stepyears,
  minor steps/.store in=\chronos@minorsteps,
  step from year/.store in=\chronos@stepfrom,
  start date/.style args={#1-#2-#3}{%
    /chronos/timeline config/.append code={%
      \tikzset{/tikz/chronos set date/.expanded={#1:#2:#3:start}}%
    },
  },
  end date/.style args={#1-#2-#3}{%
    /chronos/timeline config/.append code={%
      \tikzset{/tikz/chronos set date/.expanded={#1:#2:#3:end}}%
    },
  },
  ce year label/.store in=\chronos@yearce,
  bce year label/.store in=\chronos@yearbce,
  timeline ce label/.store in=\chronos@ce,
  timeline bce label/.store in=\chronos@bce,
  timeline width/.store in=\chronos@width,
  timeline height/.store in=\chronos@height,
  width/.forward to=/chronos/timeline width,
  height/.forward to=/chronos/timeline height,
  timeline border height/.store in=\chronos@borderheight,
  timeline border inner colour/.code={\colorlet{chronos@borderinner}{#1}},
  timeline border outer colour/.code={\colorlet{chronos@borderouter}{#1}},
  timeline mark eras/.is if=chronos@markeras,
  timeline margin/.store in=\chronos@timelinemargin,
  timeline font/.store in=\chronos@timelinefont,
  timeline years anchor/.store in=\chronos@timelineyearsanchor,
  timeline years set/.store in=\chronos@timelineyears,
  timeline years/.is choice,
  timeline years/.forward to=/chronos/timeline years set,
  timeline years/above/.code={%
    \tikzset{%
      /chronos/timeline@years/.style={above, anchor=\chronos@timelineyearsanchor, yshift=.5*\chronos@height},
      /chronos/timeline years anchor=south,
    }%
  },
  timeline years/below/.code={%
    \tikzset{%
      /chronos/timeline@years/.style={below, anchor=\chronos@timelineyearsanchor, yshift=-.5*\chronos@height},
      /chronos/timeline years anchor=north,
    }%
  },
  timeline years/on line/.code={%
    \chronos@yearsonlinetrue
    \tikzset{%
      /chronos/timeline@years/.style={anchor=\chronos@timelineyearsanchor},
      /chronos/timeline years anchor=center,
    }%
  },
  only years/.code={%
    \edef\tempa{}%
    \edef\tempb{#1}%
    \ifx\tempa\tempb\chronos@setdateformat{!Y}\else\chronos@setdateformat{#1}\fi
    \tikzset{%
      /tikz/chronos date/.style={%
        /tikz/chronos set date/.expanded={##1:01:01:thing}%
      },
      /tikz/chronos period date/.style={%
        /tikz/chronos set date/.expanded={##1:01:01:otherthing}%
      },
    }%
  },
  only text/.code={%
    \tikzset{/chronos/only years}%
    \chronos@setdateformat{}%
    \chronos@onlytexttrue
  },
  year zero/.is if=chronos@yearzero,
  background/.code={%
    \colorlet{chronos@background}{#1}%
  },
  timeline marks/.is if=chronos@marks,
  timeline minor marks/.is if=chronos@marks@minor,
  timeline show years/.is if=chronos@timeline@showyears,
  timeline no years/.code={%
    \tikzset{%
      /chronos/timeline show years=false,
    }%
  },
  lines/.style={draw, {Triangle[width=0pt 3,reversed,length=0pt 1.5]}-{Triangle[width=0pt 3,reversed,length=0pt 1.5]}, shorten <={.5*\chronos@height+\chronos@borderheight}},
  events/.style={fill=chronos@background, fill opacity=.75, text opacity=1, draw opacity=1, rounded corners, align=center, font=\footnotesize},
  period/.style={draw},
  period event line/.style={/chronos/lines},
  period event/.style={/chronos/events},
  event line/.style={/chronos/lines},
  event/.style={/chronos/events},
  event years on line/.is if=chronos@eventyearsonline,
  event year on line/.style={/chronos/timeline@years, /chronos/timeline year on line},
  event dates split/.is if=chronos@eventdatessplit,
  event date split/.style={/chronos/event},
  event distance/.store in=\chronos@eventdistance,
  special date/.store in=\chronos@specialdate,
  timeline@line/.style={draw},
  timeline line/.chronos too=timeline@line,
  timeline year off line/.style={fill=chronos@background, text opacity=1, align=center, fill opacity=.75},
  timeline mark off line/.style={draw, {Triangle[width=0pt 3,reversed,length=0pt 1.5]}-, thin, shorten >=-2pt},
  timeline minor mark off line/.style={draw, {Triangle[width=0pt 3,reversed,length=0pt 1.5]}-, very thin, shorten >=-1pt},
  timeline year on line/.style={text=chronos@background, inner sep=1pt, align=center},
  timeline mark on line/.style={draw=chronos@background, shorten >=1.5pt},
  timeline minor mark on line/.style={draw=chronos@background, shorten >=1.5pt},
  timeline mark too/.code={%
    \tikzset{%
      /chronos/.cd,
      timeline mark on line/.append style={#1},
      timeline mark off line/.append style={#1},
    }%
  },
  timeline minor mark too/.code={%
    \tikzset{%
      /chronos/.cd,
      timeline minor marks,
      timeline minor mark on line/.append style={#1},
      timeline minor mark off line/.append style={#1},
    }%
  },
  timeline year too/.code={%
    \tikzset{%
      /chronos/.cd,
      timeline year on line/.append style={#1},
      timeline year off line/.append style={#1},
    }%
  },
  timeline mark/.forward to=/chronos/timeline mark too,
  timeline minor mark/.forward to=/chronos/timeline mark too,
  timeline year/.forward to=/chronos/timeline year too,
  start date=1001-10-01,
  end date=1003-06-14,
  timeline width=100mm,
  timeline height=1pt,
  timeline border height=0pt,
  chronos date=1850-01-01,
  chronos period date=1851-01-01,
  step years=1,
  minor steps=1,
  timeline years=above,
  background=white,
  timeline border inner colour=black,
  timeline border outer colour=chronos@background,
  step from year=none,
  special date=none,
  ce year label={\textsc{ce}},
  bce year label={\textsc{bce}},
  event distance=-10pt,
  timeline ce label={CE},
  timeline bce label={BCE},
  timeline margin=10pt,
  timeline font=\sffamily,
}
\NewDocumentCommand \chronosevent { O {} m O {} +m D () { \chronos@eventdistance } }
{%
  \tikzset{%
    chronos date/.expanded={#2},
  }%
  \pgfmathsetmacro\chronos@offset{(#5 < 0pt) ? (#5-.5*\chronos@height-\chronos@borderheight) : (#5+.5*\chronos@height+\chronos@borderheight)}%
  \pgfmathsetmacro\chronos@anchor{(#5 < 0pt) ? "north" : "south"}%
  \scoped[on background layer]{%
    \ifchronos@eventdatessplit
      \ifchronos@onlytext\relax
      \else
        \pgfmathsetmacro\chronos@invanchor{(#5 < 0pt) ? "south" : "north"}%
        \path [postaction={/chronos/event line, #1}] ({(\thechronos@thingdate-\thechronos@startdate)*\chronos@unit pt},0) -- +(0,-\chronos@offset pt) node [anchor=\chronos@invanchor, /chronos/event date split, #3] {\chronos@showdate{thing}};
      \fi
      \path [postaction={/chronos/event line, #1}] ({(\thechronos@thingdate-\thechronos@startdate)*\chronos@unit pt},0) -- +(0,\chronos@offset pt) node [anchor=\chronos@anchor, /chronos/event, #3] {#4};
    \else
      \path [postaction={/chronos/event line, #1}] ({(\thechronos@thingdate-\thechronos@startdate)*\chronos@unit pt},0) -- +(0,\chronos@offset pt) node [anchor=\chronos@anchor, /chronos/event, #3] {\ifchronos@onlytext\relax\else\chronos@showdate{thing}\\\fi#4};
    \fi
  }%
  \ifchronos@eventyearsonline
    \edef\tempa{none}%
    \edef\tempb{\chronos@specialdate}%
    \ifx\tempa\tempb\else\let\chronos@thingyear\chronos@specialdate\tikzset{/chronos/special date=none}\fi
    \node [/chronos/.cd, event year on line] at ({(\thechronos@thingdate-\thechronos@startdate)*\chronos@unit pt},0) {\chronos@thingyear};
  \fi
}
\NewDocumentCommand \chronosspecialdate { m }
{%
  \tikzset{%
    /chronos/special date=#1,
  }%
}
\NewDocumentCommand \chronosperiod { O {} m O {} m O {} +m D () { \chronos@eventdistance } }
{%
  \tikzset{%
    chronos date/.expanded={#2}, chronos period date/.expanded={#4}
  }%
  \pgfmathsetmacro\chronos@offset{(#7 < 0pt) ? (#7-.5*\chronos@height-\chronos@borderheight) : (#7+.5*\chronos@height+\chronos@borderheight)}%
  \pgfmathsetmacro\chronos@anchor{(#7 < 0pt) ? "north" : "south"}%
  \ifchronos@yearsonline
    \pgfmathsetmacro\chronos@borderoffset{(#7 < 0pt) ? (-.5*\chronos@height-.5*\chronos@borderheight) : (.5*\chronos@height+.5*\chronos@borderheight)}%
    \path [postaction={line width=\chronos@borderheight, /chronos/period, blend mode=overlay, #1}] ({(\thechronos@thingdate-\thechronos@startdate)*\chronos@unit pt},\chronos@borderoffset pt) -- ({(\thechronos@otherthingdate-\thechronos@startdate)*\chronos@unit pt},\chronos@borderoffset pt);
  \else
    \path [postaction={line width=\chronos@height, /chronos/period, #1}] ({(\thechronos@thingdate-\thechronos@startdate)*\chronos@unit pt},0) -- ({(\thechronos@otherthingdate-\thechronos@startdate)*\chronos@unit pt},0);
  \fi
  \scoped[on background layer]{\path [postaction={/chronos/period event line, #3}] ({(.5*\thechronos@otherthingdate+.5*\thechronos@thingdate-\thechronos@startdate)*\chronos@unit pt},0) -- +(0,\chronos@offset pt) node [anchor=\chronos@anchor, /chronos/period event, #5] {\ifchronos@onlytext\relax\else\chronos@showdate{thing}--\chronos@showdate{otherthing}\\\fi#6};}
}
\makeatother
\begin{document}
\begin{tikzpicture}
  [
    chronos={%
      period/.style={draw=gray},
      start date=2002-01-01,
      end date=2016-12-31,
      timeline line={gray, -Latex},
      timeline marks,
      timeline minor marks,
      timeline mark={gray},
      timeline minor mark={gray},
      minor steps=4,
      timeline year={font=\tiny, fill=none},
      timeline margin=5mm,
      timeline width=90mm,
    }
  ]
\end{tikzpicture}

\begin{tikzpicture}
  [
    chronos={%
      period/.style={draw=gray},
      start date=2002-01-01,
      end date=2016-12-31,
      timeline line={darkgray, -Stealth},
      timeline marks,
      timeline minor marks,
      timeline mark={darkgray, ultra thick},
      timeline minor mark={darkgray, thick},
      minor steps=4,
      step years=2,
      timeline year={fill=none},
      timeline margin=5mm,
      timeline width=90mm,
      timeline year={text=darkgray, rotate=90},
      timeline years anchor=west,
    }
  ]
\end{tikzpicture}
\end{document}
  • No need to further develop my answer, I guess... This is awesome! But, what the heck is chronos? Is it still in development? I coudn't find it on CTAN, and if it's on developement I'm hoping for a better manual as that from chronology. ;D – Guilherme Zanotelli Jan 18 '17 at 6:43
  • @GuilhermeZanotelli It is not a real package. I just made it to answer questions about chronosys, which is unmodifiable and then adapted it a bit each time I found I needed to to answer another timeline question. However, I am beginning to think that it might be more convenient to turn it into a package. If anybody might be interested in using it. Right now, the only documentation is scattered around this site. – cfr Jan 19 '17 at 0:11
  • @GuilhermeZanotelli If it makes it to CTAN, it will get a manual .... At least, I've not uploaded a package to CTAN without one yet. – cfr Jan 19 '17 at 0:14
  • This fails using Tex Live 2019 (either pdflatex or lualatex): ! LaTeX3 Error: Variant form 'c' deprecated for base form (LaTeX3) '\chronos_year_shorten:n'. One should not change an argument (LaTeX3) from type 'n' to type 'c': use a 'v' variant? – gerrit Nov 18 at 10:57
  • 1
    Found it: it is incompatible with the breqn package (2018/09/14 v0.98f). Inserting a \usepackage{breqn} triggers the failure mentioned in the previous comment. – gerrit Nov 18 at 13:18

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.