[Tex/LaTex] Customising a tikz calendar

calendartikz-pgf

I am trying to make a simple calendar, this is how far I have got so far…

\documentclass{article}
\usepackage[nomessages]{fp}% http://ctan.org/pkg/fp
\usepackage{tikz}
\usepackage{ifthen}
\usetikzlibrary{arrows,shapes}
\usetikzlibrary{positioning,calendar,er}
\usetikzlibrary{decorations.markings}
\usetikzlibrary{shapes.geometric}
\usepackage[margin=0.5in, paperwidth=15.8in, paperheight=8.5in]{geometry}
\usepackage{geometry}
\pagenumbering{gobble}

\makeatletter%

\newcommand{\modulo}[2]{%
  \FPeval{\result}{trunc(#1-(#2*trunc(#1/#2,0)),0)}\result%
}

    \pgfkeys{/pgf/calendar/even/.code={%
            \pgfmathparse{int(mod(\pgfcalendarifdatejulian,2))}
            \ifnum 
              \pgfmathresult=0
            \relax\pgfcalendarmatchestrue\fi%
    }}%

\tikzoption{day headings}{\tikzstyle{day heading}=[#1]}
\tikzstyle{day heading}=[]
\tikzstyle{day letter headings}=[
    execute before day scope={ \ifdate{day of month=1}{%
      \pgfmathsetlength{\pgf@ya}{\tikz@lib@cal@yshift}%
      \pgfmathsetlength\pgf@xa{\tikz@lib@cal@xshift}%
      \pgftransformyshift{-\pgf@ya}
      \foreach \d/\l in {0/M,1/T,2/W,3/T,4/F,5/S,6/S} {
        \pgf@xa=\d\pgf@xa%
        \pgftransformxshift{\pgf@xa}%
        \pgftransformyshift{\pgf@ya}%
        \node[every day,day heading]{\l};%
      } 
    }{}%
  }%
]

\makeatother%

\begin{document}
    \begin{tikzpicture}[every calendar/.style={
        week list,
        month label above centered,
        day xshift = 0.8cm,
        day headings=black,
        day letter headings,
        }]
        \matrix[column sep=5em, row sep=3em] {
            \calendar[dates=2012-01-01 to 2012-01-last] if (even) [orange]; &
            \calendar[dates=2012-02-01 to 2012-02-last] if (even) [orange]; &
            \calendar[dates=2012-03-01 to 2012-03-last] if (even) [orange]; \\
            \calendar[dates=2012-04-01 to 2012-04-last] if (even) [orange]; &
            \calendar[dates=2012-05-01 to 2012-05-last] if (even) [orange]; &
            \calendar[dates=2012-06-01 to 2012-06-last] if (even) [orange]; \\
            \calendar[dates=2012-07-01 to 2012-07-last] if (even) [orange]; &
            \calendar[dates=2012-08-01 to 2012-08-last] if (even) [orange]; &
            \calendar[dates=2012-09-01 to 2012-09-last] if (even) [orange]; \\
            \calendar[dates=2012-10-01 to 2012-10-last] if (even) [orange]; &
                \calendar[dates=2012-11-01 to 2012-11-last] if (even) [orange]; &
            \calendar[dates=2012-12-01 to 2012-12-last] if (even) [orange]; \\
        };

    \end{tikzpicture}
\end{document}

Now I want to colour the days alternately, i.e. jan 1, 3, 5… would be one colour and the rest another colour, for the whole year. This could either be a different font colour for the number or a background fill colour, I don't really mind, as long as there is an pretty way to distinguish odd and even numbered days of the year easily.

ps: this is just a minor annoyance, but my calendar is appearing on page 2 of a pdf file with a blank first page, and I'm not sure why. I'm making it like pdflatex wim_cal.tex wim_cal.pdf.


After some hours of mucking around I have made some small progress and edited my tex sample above (you can see the diff..)
The first blank page thing is fixed.

Now I think I am almost there, if you search for the part \pgfcalendarifdatejulian , when I replace that with an even number then I get all days orange on the calendar, when I replace it with an odd number then I get all days black. But with \pgfcalendarifdatejulian as is, I get an error like ! Dimension too large. when doing pdflatex. What am I missing now?


Edit: I still have not solved this problem.. should I post a new, update question with my latest attempts?

Best Answer

You could specify an if condition, such as

\calendar[dates=2012-01-01 to 2012-01-last] if (Monday,Wednesday,Friday,Sunday) [red];

calendar

Your calendar is appearing on page 2 because it's too high for the text area. You will get an Overfull \vbox warning and the tikzpicture is moved to the next page. Make it a bit smaller or adjust the text area.