I want to create a simple week-based schedule in some automatic fashion. Like a cleaning schedule among roommates, a winter-service schedule among neighbors etc.

Basically I want to transfer a simple case distinction rule like

x % n == 0   -> party_1 in charge
x % n == 1   -> party_2 in charge
x % n == n-1 -> party_n in charge

(where x is the current week-number)

into a DIN-A4 calendar like schedule. Where e.g. each month is a block, each weak is a line in that block which is annotated with the assigned party and week-number (and possibly colorized).

The calendar library of tikz looks promising, but I can't find a command to access the weeknumber (for use in if/ifdate clauses).

Sure, I can always autogenerate 52 if-clauses for a tikz-calendar command, but perhaps there is a more elegant way?

1 Answer 1


I did a little bit of rtfm and I've come up with some macros for that task.

First, we need to compute the 'day of the year' for a given date, i.e. the number of days that have passed since the beginning of a year with respect to a given date:


The initbegin macro initializes the begincnt counter to the julian day number (JDN) of the 1st of January we want to use in our calendar.

doy gets the JDN of a 2014 date as input and sets the counter given as first argument to the day-of-the-year result.

With that we can define a weak of the year (woy) macro:


Again, a result counter is the first argument and 2nd argument is a counter that contains the JDN of a date.

The yearoff macro returns 2 for a 2014 date - it is needed as 'correction' for years where the first of January is not a Monday. Its code:



With that we are (nearly) ready to define a custom pgf-key for ifdate-clauses in PGF- and TikZ-Calendar constructs:


\pgfkeys{/pgf/calendar/modb/.cd,.value required,.code={

This filter uses another custom macro mod to compute the modulo (\cntp contains the number of parties):



We can use the filter like this:

On 2014-01-06 the 2nd party is \pgfcalendarifdate{2014-01-06}{modb=1}{not} in charge.

Or in a TikZ-calendar command:

  \calendar[dates=2014-01-01 to 2014-03-last, week list,month label above centered]
    if (modb=2) [nodes={fill=blue!60}]

(which colorizes all days where the third party is in charge)

Or as part of a calendar style:

\begin{tikzpicture}[every calendar/.style={
  if={(modb=0) [nodes={fill=yellow!60}]}
  • In the \woy definition, to have the desired week number, you do not want to advance the counter #1 by 1 at the end.
    – fyusuf-a
    Sep 20, 2015 at 18:27

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .