5

I would like to generate a time line, but that starts from a given month in a year and not just from January. Also the end of the time line should be able to modify such that it can be different from December. I like the chronosys package, but this seems not to be possible as it gives errors when compiling while it is working when just specifying the year.

Also for events it is possible to specify a specific data, but for chronoperiods, these always span a whole year, from january to december whilst I would like to indicate just a few months. How can I achieve this.

Below the working code and non-working to show what I am aiming for:

\documentclass{beamer}

\usepackage{chronosys}

\begin{document}


% working
\catcode`\@=11
\def\chron@selectmonth#1{\ifcase#1\or January\or February\or
March\or April\or May\or June\or
July\or August\or September\or
October\or November\or December\fi}
\definechronoperiode{Leave}[color=red, textstyle=\it]

\begin{frame}
\frametitle{Time line}
\startchronology[startyear=2010,stopyear=2016]
    \chronoLeave{2011}{2012}{Leave}
    \chronoevent{1/10/2015}{test}
\endchronology
\end{frame}

% what I want -> not working

\begin{frame}
\frametitle{Time line}
\startchronology[startyear=01/10/2010,stopyear=01/10/2016]
    \chronoLeave{10/10/2011}{16/01/2012}{Leave}
    \chronoevent{1/10/2015}{test}
\endchronology
\end{frame}
\end{document}
  • Either accept the limitations of chronosys or choose another package. It would be easier to write your own package from scratch than it would be to modify this one. It uses TikZ but it uses none of TikZ's framework, making it virtually impossible to modify. See this question for a similar request to modify the package, discussion of the difficulties and one of the alternatives. – cfr Jun 2 '16 at 13:15
5

Current version of chronos is available at:
https://tex.stackexchange.com/a/342699/ (2016-12-06)

Here's an enhanced version of the code I posted in this answer as a substitute for chronosys, since the latter is so difficult to modify.

In addition to the keys explained there,

  • event is a style used for one-day events;
  • event line is a style used for the line drawn to these events;
  • period is a style used for drawing the line indicating the duration on the timeline;
  • period event is a style used for longer events;
  • period event line is a style used for the line drawn to these events.

Two new commands are provided:

  • \chronosevent [<options for event line>] {<date>} [<options for event node>] {<text>} (<distance of event node from timeline>)
  • \chronosperiod [<options for line marking period on timeline>] [<start date>] [<options for period event line>] {<end date>} [<options for period event node>] {<text>} (<distance of period event node from timeline>)

The optional arguments allow the default styles to be overridden for particular events/period events.

\documentclass[tikz,multi,border=10pt]{standalone}
\usepackage{datenumber,xparse}
\usetikzlibrary{arrows.meta,backgrounds}
\newcounter{chronosstartdate}
\newcounter{chronosenddate}
\newcounter{chronosstartyear}
\newcounter{chronosendyear}
\newcounter{chronosyeardate}
\newcounter{chronosthingdate}
\newcounter{chronosotherthingdate}
\pgfkeys{/pgf/number format,
  int detect,
  set thousands separator={},
}
\tikzset{
  chronos/.code={% https://tex.stackexchange.com/a/159856/ - Claudio Fiandrino
    \tikzset{%
      align=center,
      anchor=mid,
      /chronos/.cd,
      #1
    }%
    \setstartyear{\chronosstartyear}%
    \setmydatenumber{chronosstartdate}{\chronosstartyear}{\chronosstartmonth}{\chronosstartday}%
    \setmydatenumber{chronosenddate}{\chronosendyear}{\chronosendmonth}{\chronosendday}%
    \pgfmathsetmacro\chronosunit{(\chronoswidth-20pt)/(\thechronosenddate-\thechronosstartdate)}%
    \draw [line width=\chronosheight] (-10pt,0) coordinate (chronos pre) -- +(\chronoswidth,0) coordinate (chronos post);
    \coordinate (chronos start) at (0,0);
    \coordinate (chronos end) at ([xshift=-10pt]chronos post);
    \setcounter{chronosstartyear}{\chronosstartyear}%
    \setcounter{chronosendyear}{\chronosendyear}%
    \def\tempa{01}%
    \ifx\chronosstartmonth\tempa
      \ifx\chronosstartday\tempa
        \else\stepcounter{chronosstartyear}%
      \fi
      \else\stepcounter{chronosstartyear}%
    \fi
    \def\tempa{12}%
    \def\tempb{31}%
    \ifx\chronosendmonth\tempa
      \ifx\chronosendday\tempb
        \stepcounter{chronosendyear}%
      \fi
    \fi
    \foreach \i in {\thechronosstartyear,...,\thechronosendyear} {%
      \setmydatenumber{chronosyeardate}{\i}{01}{01}%
      \node [above, anchor=south, yshift=.5*\chronosheight] at ({(\thechronosyeardate-\thechronosstartdate)*\chronosunit pt},0) {\i}; }
  },
  chronos set date/.code args={#1-#2-#3:#4}{%
    \tikzset{%
      /chronos/.cd,
      #4 year={#1},
      #4 month={#2},
      #4 day={#3},
    }%
    \setmydatenumber{chronos#4date}{\csname chronos#4year\endcsname}{\csname chronos#4month\endcsname}{\csname chronos#4day\endcsname}%
  },
  chronos date/.style args={#1-#2-#3}{%
    chronos set date/.expanded={#1-#2-#3:thing}%
  },
  chronos period date/.style args={#1-#2-#3}{%
    chronos set date/.expanded={#1-#2-#3:otherthing}%
  },
  /chronos/.search also={/tikz},
  /chronos/.cd,
  start year/.store in=\chronosstartyear,
  start month/.store in=\chronosstartmonth,
  start day/.store in=\chronosstartday,
  end year/.store in=\chronosendyear,
  end month/.store in=\chronosendmonth,
  end day/.store in=\chronosendday,
  thing year/.store in=\chronosthingyear,
  thing month/.store in=\chronosthingmonth,
  thing day/.store in=\chronosthingday,
  otherthing year/.store in=\chronosotherthingyear,
  otherthing month/.store in=\chronosotherthingmonth,
  otherthing day/.store in=\chronosotherthingday,
  start date/.style args={#1-#2-#3}{%
    start year={#1},
    start month={#2},
    start day={#3},
  },
  end date/.style args={#1-#2-#3}{%
    end year={#1},
    end month={#2},
    end day={#3},
  },
  width/.store in=\chronoswidth,
  height/.store in=\chronosheight,
  period/.style={draw=gray},
  period event line/.style={draw=gray, -{Triangle[width=1.5pt, reversed, length=.75pt, fill=gray]}},
  period event/.style={anchor=north, fill=gray!25, draw=gray, rounded corners, align=center, font=\footnotesize},
  event line/.style={draw=gray, -{Triangle[width=1.5pt, reversed, length=.75pt, fill=gray]}},
  event/.style={anchor=north, fill=gray!25, draw=gray, rounded corners, align=center, font=\footnotesize},
  start date=1001-10-01,
  end date=1003-06-14,
  width=100mm,
  height=1pt,
  chronos date=1850-01-01,
  chronos period date=1851-01-01,
}
\NewDocumentCommand \chronosevent { O {} m O {} +m D () { -10pt-.5*\chronosheight } }
{%
  \scoped[on background layer]{\path [postaction={/chronos/event line, #1}, chronos date/.expanded={#2}] ({(\thechronosthingdate-\thechronosstartdate)*\chronosunit pt},0) -- +(0,#5) node [/chronos/event, #3] {\chronosthingday/\chronosthingmonth/\chronosthingyear\\#4};}
}
\NewDocumentCommand \chronosperiod { O {} m O {} m O {} +m D () { -10pt-.5*\chronosheight } }
{%
  \tikzset{%
    chronos date/.expanded={#2}, chronos period date/.expanded={#4}
  }
  \path [postaction={line width=\chronosheight, /chronos/period, #1}] ({(\thechronosthingdate-\thechronosstartdate)*\chronosunit pt},0) -- ({(\thechronosotherthingdate-\thechronosstartdate)*\chronosunit pt},0);
  \scoped[on background layer]{\path [postaction={/chronos/period event line, #3}] ({(.5*\thechronosotherthingdate+.5*\thechronosthingdate-\thechronosstartdate)*\chronosunit pt},0) -- +(0,#7) node [/chronos/period event, #5] {\chronosthingday/\chronosthingmonth/\chronosthingyear--\chronosotherthingday/\chronosotherthingmonth/\chronosotherthingyear\\#6};}
}
\begin{document}
\begin{tikzpicture}
  [
    chronos={%
      width=120mm,
      height=10pt,
      start date=2010-10-01,
      end date=2016-10-01,
      period/.style={draw=green},
      event line/.append style={draw=blue},
      period event line/.append style={draw=green},
      event/.append style={fill=blue!25, draw=blue, text=blue},
      period event/.append style={fill=green!25, draw=green!75!black, text=green!75!black},
    }
  ]
  \chronosperiod [draw=red] {2011-10-10} [draw=red] {2012-01-16} [fill=red!25, draw=red, text=red] {Leave}
  \chronosperiod {2013-03-23} {2014-05-27} {training}
  \chronosevent {2015-10-01} {test}
\end{tikzpicture}
\end{document}

chronosys substitute

  • Wonderful answer!! – A Feldman Jun 3 '16 at 3:11
  • @AFeldman Thank you. Though I doubt it is what the OP wants ;). But I thought you might like it :-). – cfr Jun 3 '16 at 3:15
  • @cfr can you separate out the code into its own file that we can \usepackage on? this is broadly useful to others, including myself. – mike-m Jan 28 '17 at 19:38
  • @mike-m It is somewhere in the vicinity of my long-term to-do list. However, I'm not currently happy with the defaults in the experimental code, so I'm not quite sure where I'm going with it. If people find it useful, hopefully, it will become a package, but I'm not sure whether it is the most useful way to do it right now. – cfr Jan 29 '17 at 2:17

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.